#C3457. GCD of a Range

    ID: 46886 Type: Default 1000ms 256MiB

GCD of a Range

GCD of a Range

You are given two integers P and Q representing a range of consecutive integers from P to Q (both inclusive). Your task is to compute the greatest common divisor (GCD) of all the integers in that range.

Observation: If P is equal to Q, then the result is simply P. Otherwise, when the range contains at least two distinct integers, there will be at least one pair of consecutive numbers. It is well-known that any two consecutive integers are co-prime (i.e., their GCD is 1), which implies that the GCD of the entire range will be 1.

Task: For each test case, output the GCD of all integers from P to Q.

The final solution must read input from stdin and write the result to stdout.

inputFormat

The first line of the input contains a single integer T, the number of test cases. Each of the following T lines contains two space-separated integers P and Q, representing the bounds of the range.

Example:

2
10 15
5 5

outputFormat

For each test case, output a single line containing the GCD of all the integers in the range from P to Q.

Example:

1
5
## sample
2
10 15
5 5
1

5

</p>