The Josephus Survivor
N people stand in a circle, numbered 1..N. Counting starts at person 1; every K-th person is eliminated until one remains. Who survives?
Input: one line with two integers N and K.
Output: the number of the surviving person.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ K ≤ 109
Sample Tests
Input 1
5 2
Output 1
3
Input 2
1 10
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.