P16567 [CodeChef] DISTGCD
普及-
题目描述

Chef has two distinct positive integers A and B.

Chef wonders how many distinct values are possible for the expression $\mathrm{gcd}(A+X,B+X)$, where X can take any non-negative integer value.

Help Chef find this value.

Here, $\mathrm{gcd}$ stands for [Greatest Common Divisor].

------ Input Format ------

  • The first line contains a single integer T — the number of test cases. Then the test cases follow.
  • The first and only line of each test case contains two distinct space separated integers A and B.

------ Output Format ------

For each testcase, output the number of distinct values of the expression $\mathrm{gcd}(A+X,B+X)$, where X can take any non-negative integer value.

------ Constraints ------

$1 ≤ T ≤ 1000$
$1 ≤ A, B ≤ 10^{9}$
$A \neq B$

----- Sample Input 1 ------
2
1 2
12 8

----- Sample Output 1 ------
1
3

----- explanation 1 ------
Test case 1: Here $\mathrm{gcd}(1+X, 2+X) = 1$ no matter what value of $X$ you choose.

Test case 2:
- If we take $X = 0$, $\mathrm{gcd}(12, 8) = 4$.
- If we take $X = 1$, $\mathrm{gcd}(13, 9) = 1$.
- If we take $X = 2$, $\mathrm{gcd}(14, 10) = 2$.

It can be shown that no other value of $\mathrm{gcd}$ is possible.

输入格式

见题面

输出格式

见题面

样例输入
2 1 2 12 8
样例输出
1 3