311059: CF1928C. Physical Education Lesson

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Physical Education Lessontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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$-th" position.

As is known, settling in "the first–$k$-th" position occurs as follows: the first $k$ people have numbers $1, 2, 3, \ldots, k$, the next $k - 2$ people have numbers $k - 1, k - 2, \ldots, 2$, the next $k$ people have numbers $1, 2, 3, \ldots, k$, and so on. Thus, the settling repeats every $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$ 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$ fit under the given constraints.

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

Input

Each test consists of multiple test cases. The first line contains a single integer $t$ ($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$ and $x$ ($1 \le x < n \le 10^9$) — Vasya's position in the line and the number Vasya received during the settling.

Output

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

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

ExampleInput
5
10 2
3 1
76 4
100 99
1000000000 500000000
Output
4
1
9
0
1
Note

In the first test case, $k$ equals $2, 3, 5, 6$ are suitable.

An example of settling for these $k$:

$k$ / №$1$$2$$3$$4$$5$$6$$7$$8$$9$$10$
$2$$1$$2$$1$$2$$1$$2$$1$$2$$1$$2$
$3$$1$$2$$3$$2$$1$$2$$3$$2$$1$$2$
$5$$1$$2$$3$$4$$5$$4$$3$$2$$1$$2$
$6$$1$$2$$3$$4$$5$$6$$5$$4$$3$$2$

In the second test case, $k = 2$ is suitable.

Output

题目大意:在体育课上,学生们按照特定的规则排队。每组的第一个人到第k个人分别被编号为1, 2, 3, ..., k,接下来的k-2个人分别被编号为k-1, k-2, ..., 2,然后下一组的k个人再次从1开始编号,如此循环。排队规则每2k-2个位置重复一次。给定一个学生Vasya在队伍中的位置n和他得到的编号x,要求找出所有可能的k的值。

输入输出数据格式:
- 输入:第一行是一个整数t,表示测试用例的数量。接下来每行包含两个整数n和x,分别表示Vasya在队伍中的位置和他得到的编号。
- 输出:对于每个测试用例,输出一个整数,表示符合条件的k的数量的个数。

示例输入:
```
5
10 2
3 1
76 4
100 99
1000000000 500000000
```

示例输出:
```
4
1
9
0
1
```

注意:题目中提到k必须大于1,且答案在给定约束下是有限的。题目大意:在体育课上,学生们按照特定的规则排队。每组的第一个人到第k个人分别被编号为1, 2, 3, ..., k,接下来的k-2个人分别被编号为k-1, k-2, ..., 2,然后下一组的k个人再次从1开始编号,如此循环。排队规则每2k-2个位置重复一次。给定一个学生Vasya在队伍中的位置n和他得到的编号x,要求找出所有可能的k的值。 输入输出数据格式: - 输入:第一行是一个整数t,表示测试用例的数量。接下来每行包含两个整数n和x,分别表示Vasya在队伍中的位置和他得到的编号。 - 输出:对于每个测试用例,输出一个整数,表示符合条件的k的数量的个数。 示例输入: ``` 5 10 2 3 1 76 4 100 99 1000000000 500000000 ``` 示例输出: ``` 4 1 9 0 1 ``` 注意:题目中提到k必须大于1,且答案在给定约束下是有限的。

加入题单

上一题 下一题 算法标签: