The Game of Pebbles
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
There is a pile of N stones. Two players alternate turns, and on each turn, a player must take between one and M stones, inclusive. The player who cannot make a move loses the game.
If you are the first player and want to ensure a win, how many stones should you take on your first turn? If winning is not possible, return 0.
Input
The input consists of two integers, N and M, where 1 ≤ N, M ≤ 1000.
Output
Output the number of stones you should take to guarantee a win, or 0 if no winning strategy exists.
Examples
Input #1
Answer #1
Submissions 2K
Acceptance rate 34%