cho.sh
Notes
Loading...

Josephus Permutation 2

Time limit

0.15s

Memory limit

128 MB

Problem

There are N people numbered from 1 to N sitting in a circle, and a positive integer K is given. Starting from person 1, repeatedly remove the K-th remaining person while counting around the circle. After a person is removed, continue counting from the next remaining person. The removal order of all N people is called the (N, K)-Josephus permutation.

Given N and K, output the (N, K)-Josephus permutation.

Input

The first line contains two integers N and K separated by a space.

  • 1 <= K <= N <= 100,000

Output

Output the Josephus permutation in the format <a1, a2, ..., aN>.