A11335 | Physical Education Lesson
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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$ .
输入格式
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.
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.
输出格式
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.
It can be proven that under the given constraints, the answer is finite.
输入输出样例
输入 #1
5 10 2 3 1 76 4 100 99 1000000000 500000000
输出 #1
4 1 9 0 1
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted