

The first line of the input contains ‘T’ denoting the number of test cases.
In the first line of each test case take two space-separated integers, ‘X’ and ‘Y’
For each test case, print the receptor number which the laser touches first.
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 5
0 <= X,Y <= 5000
Time Limit: 1 sec
Explanation:
First, we will reduce ‘X’ and ‘Y’ by their common factors because that won’t impact our final outcome. i.e. the result of pair k*X and k*Y will be the same as the result of pair ‘X’ and ‘Y’. This is because k*X and k*Y can be just seen as a zoomed-up version of the other pair.
We can assume that the laser never gets reflected rather it travels in a straight line and we just invert the mirror to find the corner it reaches.
Eg:
Image 1:
Image 2:
The figure below shows the reflection of the mirror horizontally and vertically. Every cell in the following table tells the top right corner number of the mirror which would be at that place.
Image 3:
If we somehow got the number of horizontal and vertical flips of the mirror then we can find the receptor the laser hit as it will hit the top right corner ( if we move in a straight line only).
From image 2, we can see that at height 2*X, the height is also equal to 3*Y
Thus 2*X= 3*Y or (number of vertical flips)*X = (number of horizontal flips)*Y
Let’s say, ‘a’= number of vertical flips and ‘b’= number of horizontal flips
Then to hit a corner a*X= b*Y, where ‘a’ and ‘b’ are integers. Then we can just solve for the smallest a and b that satisfies this equation.
Algorithm:
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
Count Repeating Digits
First Digit One
Special Digit Numbers