Vasya and Socks
Practice this coding question on Coding Gurukul.
Problem statement
Vasya is preparing for a training camp with n clean pairs of socks. He uses one fresh pair every morning and discards it that evening. The camp laundry delivers one replacement pair late in the evening on every m-th day, and he wants to know how long his supply will last without missing a morning. Your task Count how many consecutive days, starting at day 1, Vasya can begin with a clean pair. Deliveries occur on days m, 2*m, 3*m and so on. A delivered pair becomes available only on the following morning. Important details Stop at the first morning when there are no clean pairs. A delivery scheduled for that evening cannot rescue the missed morning. However, if Vasya used his last pair that morning and a delivery arrives that evening, he can continue the next day. Each delivery contains exactly one pair. Worked example With n = 4 and m = 3, Vasya uses a pair on days 1, 2 and 3, then receives one pair on the evening of day 3. He has enough for days 4 and 5, but none for the morning of day 6. The answer is 5; the evening delivery on day 6 is too late. With one initial pair and m = 2, only day 1 is possible.
Input format
Read n m on one line.
Output format
Print the number of consecutive days with a clean pair available in the morning.
Constraints
1 <= n <= 100; 2 <= m <= 100.
Sample input
4 3
Sample output
5
Sign in to run or submit a solution in C++, Java or Python.