题目描述
Given two integers A and B.
Let P denote a sequence of N [prime numbers] such that the sum of the sequence is A.
Let Q denote a sequence of M prime numbers such that the sum of the sequence is B.
Let X denote the maximum absolute difference between P_{i} and Q_{j} among all valid pairs (i,j) such that (1 ≤ i ≤ N) and (1 ≤ j ≤ M).
Find the minimum possible value of X over all possible sequences P and Q.
More formally, for all possible sequences P and Q, find the minimum value of $\texttt{max}(|P_{i} - Q_{j}|)$, where (1 ≤ i ≤ N) and (1 ≤ j ≤ M).
Print -1 if any one of the sequences cannot be formed.
Note that, |X| denotes the absolute value of a number X. For example, |-4| = 4 and |7| = 7.
------ Input Format ------
- First line will contain T, the number of test cases. Then the test cases follow.
- Each test case contains two integers A and B.
------ Output Format ------
For each test case, find the minimum possible value of the maximum absolute difference between P_{i} and Q_{j} for (1 ≤ i ≤ N) and (1 ≤ j ≤ M). If any of the sequences can not be formed, print -1 instead.
------ Constraints ------
$1 ≤T ≤10^{5}$
$1 ≤A ≤10^{18}$
$1 ≤B ≤10^{18}$
----- Sample Input 1 ------
2
3 6
3 2
----- Sample Output 1 ------
0
1
----- explanation 1 ------
Test case $1$: Let $P=\{3\}$ and $Q=\{3,3\}$.
The maximum absolute difference is $0$. It can be shown that the maximum absolute difference can not be less than $0$.
Test case $2$: The only possible sequences are $P=\{3\}$ and $Q=\{2\}$.
The maximum absolute difference is $1$. It can be shown that the maximum absolute difference can not be less than $1$.
输入格式
见题面
输出格式
见题面