Under construction

Still being built. Things may change

Total Number of Counts

Interview

Time limit1sMemory limit512 MB

Summary
Given N bills and bundle size M, repeatedly count items and group them into bundles of M until no bundle can form, then print the total number of counts.
Level

Easy3 of 10

Topics
Math, Simulation, Implementation, Recursion
Solved
No attempts yet

Problem

Ho-geun went from Korea to the United States to study. To cover his living expenses, he took the won he had brought and went to an exchange office to change it all into dollars. The office had no bills other than 1-dollar bills, so he exchanged everything into 1-dollar bills and brought them back to his lodging. He knows the amount he exchanged, but he feels uneasy and wants to count it once more at his lodging.

Ho-geun first counts the 1-dollar bills one by one, making a bundle of M bills. He then counts the newly made bundles one by one, gathering M bundles into one again. He repeats this process until no more bundles can be made. Find the total number of times Ho-geun counts, including the bundles.

For example, when N is 13 and M is 10, counting 13 dollars requires counting the 1-dollar bills 13 times, making a bundle of 10 bills, and then counting that one bundle once more, for a total of 14 counts.

Input

The first line gives the exchanged amount N and the bundle size M. (2 ≤ N ≤ 100,000, 2 ≤ M ≤ N)

Output

Print the total number of counts.

Examples2

  1. Example 1

    Input
    13 10
    
    Expected output
    14
    
  2. Example 2

    Input
    100 8
    
    Expected output
    113