#P1928C. Physical Education Lesson
Physical Education Lesson
题面翻译
定义一个 位数列为前 个数是 ,接下来 个数是 ,在接下来 个数是 ,如此循环。
现在你知道这个数列的第 项是 ,求有多少种不同的可能的 。
题目描述
In a well-known school, a physical education lesson took place. As usual, everyone was lined up and asked to settle in "the first– -th" position.
As is known, settling in "the first– -th" position occurs as follows: the first people have numbers , the next people have numbers , the next people have numbers , and so on. Thus, the settling repeats every positions. Examples of settling are given in the "Note" section.
The boy Vasya constantly forgets everything. For example, he forgot the number 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 fit under the given constraints.
Note that the settling exists if and only if . In particular, this means that the settling does not exist for .
输入格式
Each test consists of multiple test cases. The first line contains a single integer ( ) — 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 and ( ) — 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 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
提示
注
在第一个测试案例中, 等于 是合适的。
为这些 定义的示例:
/ № | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
在第二个测试用例中, 是合适的。
相关
在以下作业中: