
ZOJ Problem Set  3141
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 squareshaped 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: Input 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. Output The output contains one line for each biscuit specifying the minimal number of splits required to break the biscuit into squares. Sample Input 2 6 7 5 5 This defines two biscuits: the one shown above which requires four splits, and a square biscuit which requires no splits. Sample Output 4 0 Source: Northeast North Ameriaca Regional Contest 2007 