cho.sh
Notes
Loading...

Josephus Permutation

Time limit

2s

Memory limit

256 MB

Problem

N people numbered from 1 to N sit in a circle. Given a positive integer K, repeatedly remove the K-th remaining person while counting around the circle. After a person is removed, counting resumes from the next remaining person. The order in which all people are removed is called the (N, K)-Josephus permutation.

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

Input

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

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

Output

Print the removed numbers in order, enclosed in angle brackets < and >. Separate adjacent numbers with a comma followed by one space: , .