1043: Jump and Remove in a ring (Clockwise)
Memory Limit:128 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:138
Solved:37
Description
Suppose a set of N consecutive integers starting are arranged in a circle.
0 1 2 3 4 5 ...... k
N-1 N-2 ...k+2 k+1
0 1 2 3 4
and let p=2. Numbers 2 4 1 0 will be removed sequentially and the number 3 remains.
Write a program to take input N and p and shows the set of numbers which are sequentially removed and the one remains at last in the following format.
Input:
N p
Output:
0 p ....
k
in which N is the number of integers, p number of counting operation and k is the number that remains at last.
0 1 2 3 4 5 ...... k
N-1 N-2 ...k+2 k+1
When the counting start at 1 and a number will be remove after p counts in a clockwise manner. The procedure does not stop until only a single integer remains.
0 1 2 3 4
and let p=2. Numbers 2 4 1 0 will be removed sequentially and the number 3 remains.
Write a program to take input N and p and shows the set of numbers which are sequentially removed and the one remains at last in the following format.
Input:
N p
Output:
0 p ....
k
in which N is the number of integers, p number of counting operation and k is the number that remains at last.
Input
5 2
Output
2 4 1 0
3
Sample Input Copy
5 2
Sample Output Copy
2 4 1 0
3