atcoder#ABC290G. [ABC290G] Edge Elimination
[ABC290G] Edge Elimination
Score : points
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.
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
1
2
1
1
2
1
0
1
999999999999999998
1
0