Question
Largest K

You are given integers X and Y (2 ≤ X, Y ≤ 109).
Find the largest integer K such that there exists a binary string S, where:

  • The count of 0s in S is X;
  • The count of 1s in S is Y;
  • There are atleast K 1s between any two occurrences of 0s in S.
Input
The first line contains a single integer T, denoting the number of test cases.
The first line of each test case contains two integers X and Y − the number of 0s and 1s in S.

Constraints
1 ≤ T ≤ 105
2 ≤ X, Y ≤ 109
Output
For each test case, output on a new line, the largest integer K, such that a binary string satisfies given conditions.
Example
Sample Input
3
2 10
3 2
10 5
Sample Output
10
1
0
Explanation
Test case 1: The ideal binary string would be 011111111110 with 10 occurrences of 1 between two 0s.
Test case 2: The ideal binary string would be 01010 with at least 1 occurrence of 1 between any two 0s.

Online