165B.md (2319B)
1 Source: https://codeforces.com/problemset/problem/165/B 2 3 B. Burning Midnight Oil 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 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  lines, drinks another cup of tea, then he writes  lines and so on: , , , ... 22 23 The expression  is regarded as the integral part from dividing number *a* by number *b*. 24 25 The moment the current value  equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished. 26 27 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. 28 29 Input 30 31 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* ≤ 109, 2 ≤ *k* ≤ 10. 32 33 Output 34 35 Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. 36 37 Examples 38 39 Input 40 41 ``` 42 7 2 43 ``` 44 45 Output 46 47 ``` 48 4 49 ``` 50 51 Input 52 53 ``` 54 59 9 55 ``` 56 57 Output 58 59 ``` 60 54 61 ``` 62 63 Note 64 65 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. 66 67 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.