Codeforces Round 112 (Div. 2)
B
Burning Midnight Oil
Codeforces
1500
原题
← AC →
翻译中…

One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of $*n*$ lines of code. Vasya is already exhausted, so he works like that: first he writes $*v*$ lines of code, drinks a cup of tea, then he writes as much as image lines, drinks another cup of tea, then he writes image lines and so on: image, image, image, ...

翻译中…

The expression image is regarded as the integral part from dividing number $*a*$ by number $*b*$.

翻译中…

The moment the current value image equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

翻译中…

Vasya is wondering, what minimum allowable value $*v*$ can take to let him write not less than $*n*$ lines of code before he falls asleep.

翻译中…

Input

翻译中…

The input consists of two integers $*n*$ and $*k*$, separated by spaces — the size of the program in lines and the productivity reduction coefficient, $1 ≤ *n* ≤ 10^{9}$, $2 ≤ *k* ≤ 10$.

翻译中…

Output

翻译中…

Print the only integer — the minimum value of $*v*$ that lets Vasya write the program in one night.

翻译中…

Note

翻译中…

In the first sample the answer is $*v* = 4$. Vasya writes the code in the following portions: first $4$ lines, then $2$, then $1$, and then Vasya falls asleep. Thus, he manages to write $4 + 2 + 1 = 7$ lines in a night and complete the task.

翻译中…

In the second sample the answer is $*v* = 54$. Vasya writes the code in the following portions: $54$, $6$. The total sum is $54 + 6 = 60$, that's even more than $*n* = 59$.

翻译中…

样例

Input #1
7 2
Output #1
4
InputCopy OutputCopy
Input #2
59 9
Output #2
54
InputCopy OutputCopy
题目信息
题号
165B
时间限制
2 s
内存限制
256 MB
标签
二分
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。