Given two integers L and B denoting the length and breadth of a rectangle respectively. The task is to calculate the sum of the area of all possible squares that comes into the rectangle.
Input: L = 4, B = 3 Output: 54 Input: L = 2, B = 5 Output: 26
The idea is to observe the count of number of squares in a rectangle.
Now, the number of squares of side 1 will be 12 as there will be two cases one as squares of 1-unit sides along the horizontal(3) and second case as squares of 1-unit sides along the vertical(4). That gives us 3*4 = 12 squares.
When the side is 2 units, one case will be as squares of side of 2 units along only one place horizontally and second case as two places vertically. So the number of squares = 6
So we can deduce that,
Number of squares of size 1*1 will be L*B
Number of squares of size 2*2 will be (L-1)(B-1)
Therefore, the number of squares with size will be:
Number of square of size K = (L-K+1)*(B-K+1)
Therefore, area of total number of squares of size K will be:
Area of total number of square of size K = (L-K+1)*(B-K+1)*K*K
Below is the implementation of above idea:
- Area of a leaf inside a square
- Ratio of area of a rectangle with the rectangle inscribed in it
- Coordinates of rectangle with given points lie inside
- Check if a point lies on or inside a rectangle | Set-2
- Check whether a given point lies on or inside the rectangle | Set 3
- Check whether a given point lies inside a rectangle or not
- Count the number of rhombi possible inside a rectangle of given size
- Area of a triangle inside a parallelogram
- Area and Perimeter of Rectangle in PL/SQL
- Maximum area of rectangle possible with given perimeter
- Number of squares of maximum area in a rectangle
- Find minimum area of rectangle with given set of coordinates
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- Area of Largest rectangle that can be inscribed in an Ellipse
- Area of largest triangle that can be inscribed within a rectangle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : chitranayal