Area, Square, Rectangle
Given two sides of rectangle, A and B you need to calculate sum of area of squares can be formed within it.
No. of squares of side i in a A x B is given by max(0, (A-i+1) * (B-i+1)).
As side of a square cannot be less than or equals 0
We will start from side = 1, Area per square = 1 * 1 = 1, No. of squares = A * B
side = 2, Area per square = 2 * 2 = 4, No. of squares = (A-1) * (B-1)
side = 3, Area per square = 3 * 3 = 9, No. of squares = (A-2) * (B-2)
and so on till No. of squares > 0.
So, multiply area per square with No. of squares and add them. Then print the result
Author’s solution can be found here.