The rule of the original Joseph game is quite simple.
At first, N people forms a circle and the person with number 1 holds the knife.
Each round, the person with knife kills the person after him and
passes the knife to the next person.
To make the game more intersting, the person with knife
kills the person who is K people after him (not always his neighbor),
and passes the knife to the person after the one being killed.
In your homework, we count and pass the knife clockwisely.
Now, we will do this in counter-clockwise way. For example,
If there are 10 people and K=3 at first.
In first round, the knife is initially hold by #1 and will be pass to #8.
Then, #7 will be killed and the knife is pass to #6.
Finally, #9 will survive.
There several test cases. The input will terminate with EOF.
Each test case contains one line with two integer N and K seperated by a space.
limits :
subtask 2 : (when you pass this subtask, you can get 20 point)
1 <= N <= 100
0 <= K <=N
Using O(N^3) algorithm is okay!
You can kill each person in O(N^2)!
subtask 1 : (when you pass this subtask, you can get another 20 point)
1 <= N <= 100000
0 <= K <= N
You have to use O(NK) algorithm!
That is, you have to kill each person in O(K)!
For each testcase, output a line with one integer.
Which is the final survivor of each test case.