1928C.md (2432B)
1 Source: https://codeforces.com/problemset/problem/1928/C 2 3 C. Physical Education Lesson 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 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. 22 23 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. 24 25 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. 26 27 Note that the settling exists if and only if $k \gt 1$. In particular, this means that the settling does not exist for $k = 1$. 28 29 Input 30 31 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. 32 33 The only line of each test case contains two integers $n$ and $x$ ($1 \le x \lt n \le 10^9$) — Vasya's position in the line and the number Vasya received during the settling. 34 35 Output 36 37 For each test case, output a single integer — the number of different $k$ that fit under the given constraints. 38 39 It can be proven that under the given constraints, the answer is finite. 40 41 Example 42 43 Input 44 45 ``` 46 5 47 48 10 2 49 50 3 1 51 52 76 4 53 54 100 99 55 56 1000000000 500000000 57 ``` 58 59 Output 60 61 ``` 62 4 63 1 64 9 65 0 66 1 67 ``` 68 69 Note 70 71 In the first test case, $k$ equals $2, 3, 5, 6$ are suitable. 72 73 An example of settling for these $k$: 74 75 | | | | | | | | | | | | 76 | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 77 | $k$ / № | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ | $9$ | $10$ | 78 | $2$ | $1$ | $2$ | $1$ | $2$ | $1$ | $2$ | $1$ | $2$ | $1$ | $2$ | 79 | $3$ | $1$ | $2$ | $3$ | $2$ | $1$ | $2$ | $3$ | $2$ | $1$ | $2$ | 80 | $5$ | $1$ | $2$ | $3$ | $4$ | $5$ | $4$ | $3$ | $2$ | $1$ | $2$ | 81 | $6$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $5$ | $4$ | $3$ | $2$ | 82 83 In the second test case, $k = 2$ is suitable.