eolymp
bolt
Try our new interface for solving problems
Problems

The algorithm of Petya

The algorithm of Petya

\includegraphics{https://static.e-olymp.com/content/b5/b59d566c4781622d1cec457e10fe3a2ae8166f99.jpg} Written on the board two positive integers \textbf{a} and \textbf{b}. Peter clears the smaller of these numbers and the number of records instead (note that it may not be an integer). From the resulting pair of numbers he is doing the same operation, and so on, until you get two matching value for the number. Free Pete from his exhausting work - write a program that the numbers \textbf{a} and \textbf{b} will give the total value of the final pair of numbers. \InputFile The first line of the input file contains the number of test cases, \textbf{t} (\textbf{1} ≤ \textbf{t} ≤ \textbf{100000}). Each test contains two positive integers \textbf{a} and \textbf{b} (\textbf{1} ≤ \textbf{a}, \textbf{b} ≤ \textbf{2·10^9}). \OutputFile For each test case output the answer to the problem. In the case of a result, output it as an irreducible fraction \textbf{x/y}. If the algorithm will run forever, output \textbf{-1}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
1 1
2 3
2 4
Output example #1
1
6
4

Example description: In the second example Peter was a result of the fraction 18/3, which after reduction to an irreducible become the number 6.

Author Evgeniy Sluzhaev