For explaining this task we need to have a look at an example.
On the picture above you can see the example of N=3. So, as you can see I gave coordinates to every single edge. Now, we will solve 2 different tasks, the number of squares and the number of rectangles. First of all let's try to calculate the number of rectangles. We will form rectangles with 2 coordinates which we will choose, one of them will be the upper left point and the second one the lower right point. So the it's easy to understand that the first coordinate (upper left coordinate) can be only in rancge ( [1,3] ,[1,3] ), so at first let's consider the first coordinate as point (1,1) how many rectangle we can form with the upper left coordinate (1,1) the lower right coordinate can be (2,2) (2,3) (2,4) (3,2) (3,3) (3,4) (4,2) (4,3) (4,4) in other words we can take the coordinate (2,2) and we can see how long can we expand it both vertically and horizontally which leaves 3x3 toatal of 9 possibilities where the upper left coordinate is (1,1). Now let's check for (1,2) the same way, we can take coordinate (2,3) and see how much we can expand it, we can expand 3 vertically and 2 horizontally which gets us total of 2x3 6 possiblities. I think we can understand now that we will have this result, 3x3,3x2,3x1, 2x3, 2x2, 2x1, 1x3,1x2,1x1 those are results where the upper left coordinate is respectively on the first second and the third line. SO, the final answer is all the multiplication pairs of numbers from 1 to N. .
Now about the squares, we can figure out the number of squares with the same way. If we consider the upper left coordinate as (1,1) then how many squares we can form? 3 totally Then if we consider all the acceptable coordinates of the first line as the upper left coordinate we will get the following result , 3,2,1.
Then on the second line it's 2,2,1. Then it's 1,1,1. As you can see the second line's answer is smaller than the previous one by 1. And the third is smaller than the second by 2.