CF1928C.Physical Education Lesson

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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

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

The boy Vasya constantly forgets everything. For example, he forgot the number kk 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 kk fit under the given constraints.

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

在一所有名的学校里,进行了一节体育课。和往常一样,所有人排成一列,并被要求按“第1–kk号”方式站位。

众所周知,“第1–kk号”站位规则如下:前 kk 个人编号分别为 1,2,3,…,k1, 2, 3, \ldots, k;接下来的 k−2k - 2 个人编号分别为 k−1,k−2,…,2k - 1, k - 2, \ldots, 2;再接下来的 kk 个人编号又为 1,2,3,…,k1, 2, 3, \ldots, k;依此类推。因此,整个编号模式每 2k−22k - 2 个位置重复一次。站位方式的具体示例见“注”部分。

男孩瓦夏总是忘事。例如,他就忘了上述的数 kk。但他记得自己在队列中的位置,以及站位时所分配到的编号。请帮助瓦夏确定:有多少个正整数 kk 满足给定的约束条件。

注意:“第1–kk号”站位方式仅当 k>1k > 1 时存在。特别地,这意味着当 k=1k = 1 时该站位方式不存在。

输入格式

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 xx(1≤x<n≤1091 \le x \lt n \le 10^9),分别表示瓦西娅在队列中的位置以及他在分配过程中得到的编号。

输出格式

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

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

对于每个测试用例,输出一个整数——满足给定约束条件的不同 kk 的个数。

可以证明,在给定约束条件下,答案是有限的。

输入输出样例

  • 输入#1

    5
    10 2
    3 1
    76 4
    100 99
    1000000000 500000000

    输出#1

    4
    1
    9
    0
    1

说明/提示

In the first test case, kk equals 2,3,5,62, 3, 5, 6 are suitable.

An example of settling for these kk:

kk / №

11

22

33

44

55

66

77

88

99

1010

22

11

22

11

22

11

22

11

22

11

22

33

11

22

33

22

11

22

33

22

11

22

55

11

22

33

44

55

44

33

22

11

22

66

11

22

33

44

55

66

55

44

33

22

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

在第一个测试用例中,k=2,3,5,6k = 2, 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

11

22

33

22

11

22

33

22

11

22

55

11

22

33

44

55

44

33

22

11

22

66

11

22

33

44

55

66

55

44

33

22

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

输入解题思路,AI测评打分。不知道怎么写?

首页