#abc321e. E - Complete Binary Tree

E - Complete Binary Tree

Score : 450450 points

问题描述

存在一棵包含 NN 个顶点的树,顶点编号为 11NN。对于每个 i (2iN)i\ (2 \leq i \leq N),存在一条边连接顶点 ii 和顶点 i2\lfloor \frac{i}{2} \rfloor。除此之外没有其他边。

在该树中,找出距离顶点 XX 距离为 KK 的顶点数量。这里,两个顶点 uuvv 之间的距离定义为连接顶点 uu 和顶点 vv 的简单路径上的边数。

你需要解决 TT 个测试用例。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a tree with NN vertices numbered 11 to NN. For each i (2iN)i\ (2 \leq i \leq N), there is an edge connecting vertex ii and vertex i2\lfloor \frac{i}{2} \rfloor. There are no other edges.

In this tree, find the number of vertices whose distance from vertex XX is KK. Here, the distance between two vertices uu and vv is defined as the number of edges in the simple path connecting vertices uu and vv.

You have TT test cases to solve.

Constraints

  • 1T1051\leq T \leq 10^5
  • 1N10181\leq N \leq 10^{18}
  • 1XN1\leq X \leq N
  • 0KN10\leq K \leq N-1
  • All input values are integers.

Input

The input is given from Standard Input in the following format, where testi\mathrm{test}_i represents the ii-th test case:

TT

test1\mathrm{test}_1

test2\mathrm{test}_2

\vdots

testT\mathrm{test}_T

Each test case is given in the following format:

NN XX KK

Output

Print TT lines.

The ii-th line (1iT)(1 \leq i \leq T) should contain the answer to the ii-th test case as an integer.

Sample Input 1

5
10 2 0
10 2 1
10 2 2
10 2 3
10 2 4

Sample Output 1

1
3
4
2
0

The tree for N=10N=10 is shown in the following figure.

Here,

  • There is 11 vertex, 22, whose distance from vertex 22 is 00.
  • There are 33 vertices, 1,4,51,4,5, whose distance from vertex 22 is 11.
  • There are 44 vertices, 3,8,9,103,8,9,10, whose distance from vertex 22 is 22.
  • There are 22 vertices, 6,76,7, whose distance from vertex 22 is 33.
  • There are no vertices whose distance from vertex 22 is 44.

Sample Input 2

10
822981260158260522 52 20
760713016476190629 2314654 57
1312150450968417 1132551176249851 7
1000000000000000000 1083770654 79
234122432773361868 170290518806790 23
536187734191890310 61862 14
594688604155374934 53288633578 39
1000000000000000000 120160810 78
89013034180999835 14853481725739 94
463213054346948152 825589 73

Sample Output 2

1556480
140703128616960
8
17732923532771328
65536
24576
2147483640
33776997205278720
7881299347898368
27021597764222976

update @ 2024/3/10 01:40:52

}