#P1928C. Physical Education Lesson

Physical Education Lesson

题面翻译

定义一个 kk 位数列为前 kk 个数是 1,2,3,,k1,2,3,\ldots,k,接下来 k2k-2 个数是 k1,k2,,2k-1,k-2,\ldots,2,在接下来 kk 个数是 1,2,3,,k1,2,3,\ldots,k,如此循环。

现在你知道这个数列的第 nn 项是 xx,求有多少种不同的可能的 kk

题目描述

In a well-known school, a physical education lesson took place. As usual, everyone was lined up and asked to settle in "the first– k k -th" position.

As is known, settling in "the first– k k -th" position occurs as follows: the first k k people have numbers 1,2,3,,k 1, 2, 3, \ldots, k , the next k2 k - 2 people have numbers k1,k2,,2 k - 1, k - 2, \ldots, 2 , the next k k people have numbers 1,2,3,,k 1, 2, 3, \ldots, k , and so on. Thus, the settling repeats every 2k2 2k - 2 positions. Examples of settling are given in the "Note" section.

The boy Vasya constantly forgets everything. For example, he forgot the number k k described above. But he remembers the position he occupied in the line, as well as the number he received during the settling. Help Vasya understand how many natural numbers k k fit under the given constraints.

Note that the settling exists if and only if k>1 k > 1 . In particular, this means that the settling does not exist for k=1 k = 1 .

输入格式

Each test consists of multiple test cases. The first line contains a single integer t t ( 1t100 1 \leq t \leq 100 ) — the number of test cases. This is followed by the description of the test cases.

The only line of each test case contains two integers n n and x x ( 1x<n109 1 \le x < n \le 10^9 ) — Vasya's position in the line and the number Vasya received during the settling.

输出格式

For each test case, output a single integer — the number of different k k that fit under the given constraints.

It can be proven that under the given constraints, the answer is finite.

样例 #1

样例输入 #1

5
10 2
3 1
76 4
100 99
1000000000 500000000

样例输出 #1

4
1
9
0
1

提示

在第一个测试案例中, kk 等于 2,3,5,62, 3, 5, 6 是合适的。

为这些 kk 定义的示例:

kk / № 11 22 33 44 55 66 77 88 99 1010
22 11 22 11 22 11 22 11 22 11 22
33 33 33
55 44 55 44
66 66 55 44 33

在第二个测试用例中, k=2k = 2 是合适的。