Square Formation
Given an a x b rectangle, your task is to cut it into squares.
On each move, you can select a rectangle and cut it into two rectangles in such a way that all side lengths remain integers.
What is the minimum possible number of moves?
Example 1:
Input: a = 3, b = 5
Output: 3
Explanation:
- Cut 3×5 → 3×3 + 3×2
- Cut 3×2 → 2×2 + 1×2
- Cut 1×2 → 1×1 + 1×1
Now all pieces are squares.
Example 2:
Input: a = 5, b = 10
Output: 1
Explanation : Cut once: 5×10 → 5×5 + 5×5 . Both pieces are already squares.
Now Your Turn!
Pick the correct output for the given inputInput: a = 2, b = 3
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= a, b <= 500