codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

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 ![](https://espresso.codeforces.com/837a798d4a0c3fe486d62834783caae40b612564.png) lines, drinks another cup of tea, then he writes ![](https://espresso.codeforces.com/6304306dbf5ca2b95ecc97210a073c7ce7046290.png) lines and so on: ![](https://espresso.codeforces.com/2cdc02455a9281e93e689009c03121270d92d1bc.png), ![](https://espresso.codeforces.com/92bb2b6b977058290f73ae4b98682b9f08f27633.png), ![](https://espresso.codeforces.com/858a837a4b30b8578ae73e5bde2c4e213fa93c32.png), ...
     22 
     23 The expression ![](https://espresso.codeforces.com/b5e5ef3e6404b5c0e793de54b932298d1825cced.png) is regarded as the integral part from dividing number *a* by number *b*.
     24 
     25 The moment the current value ![](https://espresso.codeforces.com/c126a89a41a4df209f523e85223b11f89735ebba.png) 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.