#P1996. 约瑟夫问题

约瑟夫问题

Description

nn people stand in a circle. Starting from the first person, they count off; the person who counts to mm leaves the circle. Then the next person resumes counting from 11. The person who counts to mm leaves the circle again. Repeat this process until everyone has left the circle. Output the labels of the people who leave, in order.

Note: This problem differs slightly from the example in the book "深入浅出-基础篇". In the book, the description is to eliminate n1n-1 children, whereas this problem continues until everyone leaves the circle.

Input Format

Input two integers n,mn, m.

Output Format

Output one line with nn integers: the labels of the people leaving the circle in order.

10 3
3 6 9 2 7 1 8 5 10 4

Hint

1m,n1001 \le m, n \le 100

Translated by ChatGPT 5