6737.Rectangle Cutting

Time Limit: 1s Memory Limit: 512MB

Given an $a \times 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?

Input Format(From the terminal/stdin)

The only input line has two integers $a$ and $b$ .

  • $1 \le a,b \le 500$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of moves.

Sample Input

Copy
3 5
 · \n

Sample Output

Copy
3
 \n
Source: CSES, Dynamic Programming, 1744

Submit

请先 登录

© 2025 FAQs