#P7851. 「JZOI-2」信号塔

「JZOI-2」信号塔

Background

All the members are thinking about organizing the anniversary celebration, but Xiao Xi just wants to slack off (moyu).

Xiao Xi wants to watch TV, but he finds there is no signal, so he goes to fix the signal tower.

Problem Description

On a straight line with 10999+110^{999}+1 points, the distance between adjacent points on the line is the same. A signal tower is built at every point, numbered from left to right as 0109990 \sim 10^{999}, where tower 00 is the TV program transmission point.

Since Xiao Xi only wants to watch TV, the signal here is transmitted only from left to right. Suppose a signal tower has strength xx, then its signal can be transmitted at most a distance of x1k\lfloor\frac{x-1}{k}\rfloor to the right.

Now Xiao Xi needs to set a strength for each signal tower, but there are too many towers and he cannot handle it, so he hands it to the "Benben robot" to do.

The Benben robot sets the strength for each signal tower in the following way.

First, set the strength of tower 00 to 103010^{30}. Then, from left to right, start from signal tower 11 and continue until signal tower 1099910^{999}. For each signal tower, find the nearest signal tower aa on its left such that the signal of tower aa can be transmitted to this signal tower, and then assign this signal tower’s strength to be the distance between these two signal towers.

Here, the distance between signal tower ii and signal tower jj is defined as ij|i-j|.

For example, when k=2k=2, the strengths of signal towers 151 \sim 5 are 1,2,3,1,51,2,3,1,5, respectively.

However, Xiao Xi still does not trust the Benben robot, so he wants to know the strength of the nn-th signal tower.

Input Format

One line with two positive integers n,kn,k.

Their meanings are as described in the statement.

Output Format

One line with one integer, indicating the strength of the signal tower with index nn.

1 1
1
5 2
5

Hint

For 10%10\% of the testdata, 1n,k2×1031\le n,k\le 2 \times 10^3.
For 30%30\% of the testdata, 1n1×1071\le n\le 1 \times 10^7.
For another 15%15\% of the testdata, k=1k=1.
For another 15%15\% of the testdata, k=2k=2.
For 100%100\% of the testdata, 1n1018,1k1061\leq n\leq10^{18},1\leq k\leq10^{6}.

Translated by ChatGPT 5