- Arnie's Dog Biscuits
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.
This defines two biscuits: the one shown above which requires four splits, and a square biscuit which requires no splits.