n people stand in a circle, numbered 1 to n. Starting the count at person 1, every k-th person is eliminated, and counting continues around the remaining circle. Find the number of the last remaining person.
One line: two integers n and k.
One line: the 1-indexed position of the survivor.
Example 1
Input
5 2
Expected
3
Explanation
Eliminations: 2,4,1,5 leave person 3 as the survivor.
Example 2
Input
1 3
Expected
1
Explanation
With one person, that person survives regardless of k.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →