题目描述
Chef has two integers A and B.
Chef wants to find the minimum value of $\texttt{lcm}(A, X) - \texttt{gcd}(B, X)$ where X is any positive integer.
Help him determine this value.
Note: $\texttt{gcd}(P, Q)$ denotes the [greatest common divisor] of P and Q and $\texttt{lcm}(P, Q)$ denotes the [least common multiple] of P and Q.
------ 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 space-separated integers A and B — the integers mentioned in the statement.
------ Output Format ------
For each test case, output the minimum value of $\texttt{lcm}(A, X) - \texttt{gcd}(B, X)$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤A, B ≤10^{9}$
----- Sample Input 1 ------
3
12 15
5 50
9 11
----- Sample Output 1 ------
9
0
8
----- explanation 1 ------
Test case $1$: For $X = 6$: $\texttt{lcm}(12, 6) - \texttt{gcd}(15, 6) = 12 - 3 = 9$ which is the minimum value required.
Test case $2$: For $X = 50$: $\texttt{lcm}(5, 50) - \texttt{gcd}(50, 50) = 50 - 50 = 0$ which is the minimum value required.
Test case $3$: For $X = 1$: $\texttt{lcm}(9, 1) - \texttt{gcd}(11, 1) = 9 - 1 = 8$ which is the minimum value required.
输入格式
见题面
输出格式
见题面