**Problem:** Consider the set of point

S = { (x,y) : x,y are non-negative integers \({\le {n}} \) }.

Find the number of squares that can be formed with vertices belonging to S and sides parallel to the axes.

**Solution**: S = {(x,y) : x,y are non-negative integers \({\le {n}} \) }

We calculate number of squares by calculating number of |x| squares ,& number of squares number of \({{n}* {n}} \) squares.

Now number of |x| squares = number of choosing one pair of lines with difference 1 parallel to x axis & integer distance x number of choosing one pair of lines to y axis with distance 1 & integer distance from y axis = \({{n}*{n}} \) = \({n^2} \)

Similarly number of \({{k}*{k}} \) squares

= \({(n-k+1)^2} \)

So total number of squares

= \({\sum_{k=1}^{n}}{{k}^{2}} \) = \({\frac{n(n+1)(2n+1)}{6}} \)

*Related*