Rectangle
Time limit1sMemory limit128 MB
Repeatedly cut the largest possible square from an n by m rectangle and count how many squares result.
- Level
Easy3 of 10
- Topics
- Math, Implementation, Simulation
- Solved
- No attempts yet
Problem
Vilibald has decided to cut a rectangular grid page of size cells into squares. First, with a single straight cut, he cuts off the largest possible square. He then removes that square and repeats the process on the remaining rectangle. Continuing in this way -- always cutting off the largest possible square -- Vilibald keeps cutting until the remaining piece is itself a square.
Given the two integers and , write a program that computes how many squares Vilibald obtains by cutting the rectangle in the manner described above.
Input
The first line contains two positive integers and , separated by a space (, ).
Output
Print, on a single line, the number of squares Vilibald obtains.