Joseph

Time limit: 5000ms
Memory limit: 256mb

Description:
The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, . . ., n, standing in circle every m-th is going to be executed. For example, when n = 6 and m = 5 then people will be executed in the order 5, 4, 6, 2, 3, 1. Given the positive integer m <= 100, n <= 100, find the order of person who will be executed.

Input:
The number of people n (positive integer <=100) and step length m (positive integer <=100).

Output:
You should ouptut n - 1 numbers, the order of executing.

Sample input:
6 5

Sample Output:
5 4 6 2 3

Hints:
You can use the doubly linked list to organize the circle of these n persons. When a person is executed, delete the corresponding node from the linked list.

Submit