11357 - Josephus Problem   

Description

Based on the original Josephus Problem introduced in class, this problem adds other rules.

1. After killing a person, it will change the direction of counting.

2. After killing a person, the counting number will increase the same value.

For example, there are 5 people, numbered 1 to 5, in a circle

and arranged in clockwise.  The step to kill is 3.

1, 2, 3 (kill 3, change the direction to counter-clockwise)

2, 1, 5, 4, 2, 1 (kill 1, change the direction to clockwise)

2, 4, 5, 2, 4, 5, 2, 4, 5 (kill 5, change the direction to counter-clockwise)

...

 

Input

The input has two positive integers, n (the number of people) and m (the number that will increase every time).

Output

The output is the order of people that were killed.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11357.c

Partial Judge Header

11357.h

Tags




Discuss