Let me go grab a hamburger real quick...

Ok, I'm back.

How many **squares** are there in the 6\(\times\)4 grid below?

Let's start by counting the smallest 1\(\times\)1 squares, this is just the same as counting the number of unit squares in a 6\(\times\)4 grid, there are \(6\times4=24\) 1 by 1 squares in the grid.

Now let's move on to the 2\(\times\)2 squares, notice that counting the number of 2\(\times\)2 squares in a 6\(\times\)4 grid is just the same as counting the number of unit squares in a 5\(\times\)3 grid. So the number of 2 by 2 squares in the grid is \(5\times3=15\).

Now the 3\(\times\)3 squares, similarly, counting the number of 3\(\times\)3 squares in a 6\(\times\)4 grid is just the same as counting the number of unit squares in a 4\(\times\)2 grid, which is \(4\times2=8\).

And again the number of 4\(\times\)4 squares in a 6\(\times\)4 grid is equal to the number of unit squares in a 3\(\times\)1 grid, which is \(3\times1=3\).

Add up all the number of squares together: \(24+15+8+3=50\). Tada! We now have our answer! There are 50 squares in a 6\(\times\)4 grid.

Mmm... the hamburger is really good...

Back on topic, in general, what is the total number of squares in an \(a\times b\) grid (where \(a\) is the **width** of the grid and \(b\) is the **height** of the grid), given \(a\geqslant b\)?

Again let's start from the 1\(\times\)1 squares, that's trivial, there's \(ab\) of them.

Now moving on to the 2\(\times\)2 squares, the number of 2\(\times\)2 squares in an \(a\times b\) grid is equal to the number of unit squares in an \((a-1)\times(b-1)\) grid.

Notice the pattern? Counting the number of \(n\times n\) squares in an \(a\times b\) grid is the same as counting the number of unit squares in an \((a-n+1)\times(b-n+1)\) grid.

The largest square that can contain in an \(a\times b\) grid given that \(a\geqslant b\) is \(b\times b\).

Hence, the total number of squares in an \(a\times b\) grid is \[ab+(a-1)(b-1)+(a-2)(b-2)+\ldots+[a-(b-2)][b-(b-2)]+[a-(b-1)][b-(b-1)]\] Or \[\sum_{i=0}^{b-1}{(a-i)(b-i)}\]

This is ugly, we don't like sigma symbols sitting around, so why not we simplify this a little bit...

\[\begin{align} \sum_{i=0}^{b-1}{(a-i)(b-i)}&=\sum_{i=0}^{b-1}{[ab-(a+b)i+i^2]} \\&=ab^2-\frac{(a+b)b(b-1)}{2}+\frac{b(b-1)(2b-1)}{6} \\&=b\left[ab-\frac{ab-a+b^2-b}{2}+\frac{2b^2-3b+1}{6}\right] \\&=\frac{b}{6}\left[6ab-3ab+3a-3b^2+3b+2b^2-3b+1\right] \\&=\frac{b}{6}\left[3ab+3a-b^2+1\right] \\&=\frac{b(b+1)(3a-b+1)}{6} \end{align}\] BOOM! There we have it! *Round of applause* *Fireworks* *Pancakes*

The total number of squares in an \(a\times b\) grid (where \(a\) is the

widthof the grid and \(b\) is theheightof the grid), given \(a\geqslant b\) is \[\frac{b(b+1)(3a-b+1)}{6}\]If \(a<b\), then we just swap the \(a\) and \(b\) around.

Special case:If \(a=b\), the above equation becomes \[\frac{a(a+1)(2a+1)}{6}\] which is the formula of the sum of squares from 1 to \(a\).

Done! Now let me finish my burger...

This is one part of Quadrilatorics.

## Comments

Sort by:

TopNewestYou should add this to the Brilliant wiki. Great note! – Sharky Kesa · 1 year, 2 months ago

Log in to reply

Cool! Thanks for that note bro, you're awesome! – Sravanth Chebrolu · 1 year, 2 months ago

Log in to reply

– Sravanth Chebrolu · 1 year, 2 months ago

Hope you finished your burger peacefully :PLog in to reply

– Tan Kenneth · 1 year, 2 months ago

Thanks, I'm glad you like the note. Well unfortunately, I think my hamburger has become stale. XDLog in to reply

Nice simple way of explaining complex situation. So many thanks. – Niranjan Khanderia · 1 year ago

Log in to reply

are you a robot, cos I need some real friends? Humanity is a lie, the computer generation is upon us. Support the cause m64^(1/2) – Kyran Gaypinathan · 1 year, 2 months ago

Log in to reply

– Tan Kenneth · 1 year, 2 months ago

No, i am 100.1% sure I'm not a robot.Log in to reply

@Tan Kenneth:) – Atanu Ghosh · 1 year, 2 months ago

What a noteLog in to reply

HEY tankenneth, you hyped? – Kyran Gaypinathan · 1 year, 2 months ago

Log in to reply

– Tan Kenneth · 1 year, 2 months ago

Oh yes I am! \(1+1=3\)Log in to reply

جميلة – Ramadan Mohamed · 1 year, 2 months ago

Log in to reply

– Tan Kenneth · 1 year, 2 months ago

Translation: beautiful!Log in to reply