Given a rectangle of sides m and n. Cut the rectangle into smaller identical pieces such that each piece is a square having maximum possible side length with no leftover part of the rectangle. Print number of such squares formed.
Input: 9 6 Output: 6 Rectangle can be cut into squares of size 3. Input: 4 2 Output: 2 Rectangle can be cut into squares of size 2.
Approach: The task is to cut the rectangle in squares with the side of length s without pieces of the rectangle left over, so s must divide both m and n. Also, the side of the square should be maximum possible, therefore, s should be the greatest common divisor of m and n.
so, s = gcd(m, n).
To find the number of squares the rectangle is cut into, the task to be done is to divide the area of a rectangle with an area of the square of size s.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Ratio of area of a rectangle with the rectangle inscribed in it
- Number of squares of side length required to cover an N*M rectangle
- Count number of squares in a rectangle
- Maximum area of rectangle possible with given perimeter
- Maximum area of rectangle inscribed in an equilateral triangle
- Largest subset of rectangles such that no rectangle fit in any other rectangle
- Minimum squares to cover a rectangle
- Minimum squares to evenly cut a rectangle
- Determine the number of squares of unit area that a given line will pass through.
- Area of a triangle inscribed in a rectangle which is inscribed in an ellipse
- Program for Area And Perimeter Of Rectangle
- Area of the biggest possible rhombus that can be inscribed in a rectangle
- Find minimum area of rectangle with given set of coordinates
- Area and Perimeter of Rectangle in PL/SQL
- Sum of Area of all possible square inside a rectangle
- Area of Largest rectangle that can be inscribed in an Ellipse
- Area of largest triangle that can be inscribed within a rectangle
- Area of a circle inscribed in a rectangle which is inscribed in a semicircle
- Area of the biggest ellipse 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 firstname.lastname@example.org. 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.