Time Limit: Java: 1000 ms / Others: 1000 ms

Memory Limit: Java: 32768 KB / Others: 32768 KB

Our discerning gourmet puppy Arnie is turning to you for a program to help him split his dog biscuits. Each biscuit is shaped like a rectangle and perforated into equal sized squares:

Unfortunately, Arnie will only eat square-shaped biscuits; therefore, he must break the biscuit into squares. Each break, termed a split, is applied to one rectangle, runs along one straight perforated line, and separates the rectangle into two pieces:

The first line of the input contains one positive integer n, the number of biscuits to split. Each of the next n lines contains two positive integers r and c, the number of rows and columns of one biscuit, separated by white space.

The output contains one line for each biscuit specifying the minimal number of splits required to break the biscuit into squares.

提交代码