10410 - Problem 2   

Description

There are N people numbered 1, 2, ..., N, standing in circle in order. Every kth is going to be executed and only the life of the last remaining person will be saved. 
Josephus is smart enough to choose the position of the last remaining person, thus saving his life. 
Given N and k, please find out the origin position which Josephus stood, and print the execution order. 

For example:
N = 6 and K = 5.
The execution order is 5 4 6 2 3
Josephus stood on position 1.

Input

A line contains two positive integers, N and k.
2 ≤ N ≤ 50, 0 < k ≤ 50

Output

First line is the execution order. Each number is separated by a space, and there is a space at the end.
Second line is the origin position which Josephus stands.
Note that you don’t have to print a newline at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss