Toyota Programming Contest 2023 Spring Qual B(AtCoder Beginner Contest 290)
翻译中…
Problem Statement
翻译中…
Solve the following problem for $T$ test cases.
翻译中…
We have a perfect $K$-ary tree of depth $D$ (with $1+K+K^2+\dots+K^D$ vertices).
Your objective is to cut some of the edges to obtain a connected component with exactly $X$ vertices.
At least how many edges must be cut to achieve the objective?
翻译中…
Constraints
翻译中…
- All values in the input are integers.
$1 \le T \le 100$$1 \le D$$2 \le K$$\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:
翻译中…
T
case_1
\vdots
case_T
翻译中…
Here, $case_i$ denotes the $i$-th test case.
Each test case is given in the following format:
翻译中…
D K X
翻译中…
Output
翻译中…
Print $T$ lines.
The $i$-th line should contain the answer to the $i$-th test case as an integer.
翻译中…
样例
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
Output #1
1
2
1
1
2
1
0
1
999999999999999998
1
0
题目信息
题号
abc290_g
时间限制
2 s
内存限制
1024 MB
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。