Problems > Candles from Stubs

Candles from Stubs

Difficulty: 1100 2000 ms 128 MB

math

You have N candles; burning one leaves a stub, and K stubs can be melted into one fresh candle (which also leaves a stub). How many candles can you burn in total?

Input: one line with two integers N and K.

Output: the total number of candles burned.

Constraints:

  • 1 ≤ N ≤ 1018
  • 2 ≤ K ≤ 109

Sample Tests

Input 1
10 3
Output 1
14
Input 2
1 2
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.