#abc290g. G - Edge Elimination
G - Edge Elimination
Score : points
问题描述
对于 个测试用例,解决以下问题。
我们拥有一棵深度为 的完美 -叉树(包含 个顶点)。
你的目标是切断一些边,以得到恰好包含 个顶点的连通分量。
至少需要切断多少条边才能达到目标?
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Solve the following problem for test cases.
We have a perfect -ary tree of depth (with vertices).
Your objective is to cut some of the edges to obtain a connected component with exactly vertices.
At least how many edges must be cut to achieve the objective?
Constraints
- All values in the input are integers.
- $\displaystyle 1 \le X \le \sum_{i=0}^{D} K^i \le 10^{18}$
Input
The input is given from Standard Input in the following format:
Here, denotes the -th test case.
Each test case is given in the following format:
Output
Print lines.
The -th line should contain the answer to the -th test case as an integer.
Sample Input 1
11
2 2 1
2 2 2
2 2 3
2 2 4
2 2 5
2 2 6
2 2 7
1 999999999999999999 1
1 999999999999999999 2
1 999999999999999999 999999999999999999
1 999999999999999999 1000000000000000000
Sample Output 1
1
2
1
1
2
1
0
1
999999999999999998
1
0
update @ 2024/3/10 12:07:40