Squares in a square

From Wikipedia, the free encyclopedia

In mathematics, a common mathematical puzzle involves finding the number of squares in a large n by n square grid. This number can be derived as follows:

  • The number of 1x1 boxes found in the grid is n2.
  • The number of 2x2 boxes found in the grid is (n − 1)2. These can be counted by counting all of the possible upper-left corners of 2x2 boxes.
  • The number of kxk boxes (1 =< k =< n) found in the grid is (nk + 1)2). These can be counted by counting all of the possible upper-left corners of kxk boxes.

It follows that the number of squares in a n by n square grid is:

x = n^2 + (n-1)^2 + (n-2)^2 + (n-3)^2 + \ldots + 1^2

or:

x = n(n + 1)(2n + 1) / 6


This combinatorics-related article is a stub. You can help Wikipedia by expanding it.