[Algorithm] Count the squares

The solution:

I noticed with n * n squares will have the kind of unit squares from 1 n and:
– Square 1 units: n^2
– Square 2 units: (A-1)^ 2
– Square 3 units: (n-2)^ 2
………………….
– N square units: (n-(A-1))^ 2 = 1.

So squares of n * n is square: n^2 + (n-1)^2 + (n-2)^2 + ... + 1 = frac{n(n+1)(2n+1)}{6}

At this point you can manually code is then, but here you have all of the master code Le Minh Hoang, you can refer to (Page 3 nhé).