DMOPC '15 Contest 2 P1 - Grumpy Dwarf

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

It's a well known fact that Xyene is a grumpy old dwarf who does nothing but smith steel bars into steel swords all day. Xyene has been doing this for so long that he can smith any steel bar into a steel sword without fail. Unfortunately, hard times are upon him: in the 21st century, the market for steel swords has crashed! It is now impossible to sell the swords he makes at a profit anymore. In fact, he can't even break even — it takes K steel swords to trade for a steel bar in today's economy.

However, the dwarven blood runs deep in Xyene, so he has sold everything he owns to buy N steel bars. He will smith these into swords and trade them for more steel bars until he has neither steel bars left nor enough steel swords to trade for steel bars, after which he will turn to his true calling of being a programmer.

From the moment when Xyene buys the N steel bars until he becomes a programmer, how many steel swords will he smith in total?

Input Specification

The first line of input will contain one integer N (1 \le N \le 1\,000), the number of steel bars Xyene starts out with.
The second line of input will contain one integer K (2 \le K \le 1\,000), the exchange rate for steel swords to steel bars.

Output Specification

Output one integer, the number of steel sword Xyene smiths.

Sample Input


Sample Output


Explanation for Sample Input

Xyene smiths 25 swords from 25 bars, which he trades for 5 more bars. He then smiths 5 more swords, which he trades for 1 more bar. He smiths his last sword and is finished, having smithed a total of 25 + 5 + 1 = 31 swords.


  • 2
    balathegreat999  commented on May 25, 2020, 11:40 a.m.

    Not Stonks

  • 0
    ZEN  commented on Nov. 30, 2017, 11:13 a.m.

    wheres the profit in this lol

    • 0
      VorticL  commented on Nov. 3, 2018, 10:35 a.m.

      It is now impossible to sell the swords he makes at a profit anymore.