$n\times n$
points? The following may be useful: $\sum\limits_{k=1}^n k^2=\frac{n(n+1)(2n+1)}{6}$
and $\sum\limits_{k=1}^n k^3=\frac{n^2(n+1)^2}{4}.$

 Four points on a Cartesian grid form a square of area
$100$
(in grid area units) with sides parallel to the grid. How many points lie on the boundary of this square?  Could you have a tilted square of area
$100$
(in grid area units) with vertices on the grid?  Simplify
$\sum_{k=0}^{n}k(nk).$
 Three points with coordinates
$(1,3),$
$(2,1)$
and$(4,2)$
lie on the perimeter of a square. What is the smallest such square (in terms of area)?
 Four points on a Cartesian grid form a square of area

How many squares with sides parallel to the grid can be built?

For a given
$k \le n,$
how many subgrids of$k\times k$
points are there? 
For a given subgrid of
$k\times k$
points, how many squares with vertices on the outer points of the subgrid can be built? 
How can we incorporate that for all values of
$k?$

… knowing that there are
$(nk+1)^2$
subgrids of$k\times k$
points and$k1$
squares (including tilted ones) per each such subgrid?

We can first count the number of different subgrids of size
$k\times k,$
then count the number of squares with vertices only on the outer points of each subgrid. This avoids counting duplicates (can you see why?).The number of subgrids of size
$k\times k$
is$(nk+1)^2$
because$nk+1$
is the number of possible horizontal (or vertical) shifts of such a subgrid.For each
$k\times k$
subgrid, a square with vertices on the outer points of the subgrid is uniquely defined by the position of the vertex on one side of the subgrid. Hence, there are$k1$
different such squares.Finally, the total number of squares is the sum over the subgrids:
$$ \begin{aligned} N&=\sum_{k=2}^{n} (k1)(nk+1)^2 \\ &=\sum_{j=1}^{n1} (nj)j^2 \\ &= n \sum_{j=1}^{n1}j^2  \sum_{j=1}^{n1}j^3 \\ &= \frac{n^2(n+1)(2n+1)}{6}\frac{n^2(n+1)^2}{4} \\ &= \frac{n^4n^2}{12}, \end{aligned} $$
where we made the change of variable$j=nk+1.$