Given a square grid, how many unique tilted squares and rectangles exist on such a grid?
For example,
2 x 2 grid has 1 tilted square.
3 x 3 grid has 4 tilted square and 4 tilted rectangles i.e. answer is 8
Tilted means they are can be formed using vertices of the grid only.
I am looking for a general formula that can be used to directly compute the number existing tilted squares and rectangles.

