War games 2
Автор задачи: Илья Гребнов, Никита Рыбак, Дмитрий Ковалёв
Первоисточник: Timus Top Coders: Third Challenge
URL первоисточника: http://acm.timus.ru/problem.aspx?space=1&num=1521&locale=ru
Задачу добавил: Spirt96
Успешно сдано решений: 1http://contest.samara.ru/ru/contests/53/
Time Limit: 1.0 second
Memory Limit: 16 MB
During the latest war games (this story is fully described in the problem "War games") the Minister of Defense of the Soviet Federation comrade Ivanov had a good chance to make sure personally, that an alertness of the Soviet Army under his command is just brilliant. But there was a thing, that continued to worry him. Being an outstanding commander, he realized, that only physical conditions of the soldiers were demonstrated. So the time came to organize one more war games and examine their mental capacity.
General Rascal was appointed to be responsible for the war games again. The general donated the allocated funds to the poor and went to bed free-hearted. In his dream, the tactics manual appeared to him and described a scheme, that allows to organize the war games absolutely free of charge.
In accordance with this scheme, the war games are divided into N phases; and N soldiers, successively numbered from 1 to N, are marching round a circle one after another, i.e. the first follows the second, the second follows the third, ..., the (N-1)-th follows the N-th, and the N-th follows the first. At each phase, a single soldier leaves the circle and goes to clean the WC, while the others continue to march. At some phase, the circle is left by a soldier, who is marching K positions before the one, who left the circle at the previous phase. A soldier, whose number is K, leaves the circle at the first phase.
Surely, Mr. Rascal cherished no hope about his soldiers' abilities to determine an order of leaving the circle. "These fools can not even paint the grass properly", - he sniffed scornfully and went to sergeant Filcher for an assistance.
The only line contains the integer numbers N (1 ≤ N ≤ 100000) and K (1 ≤ K ≤ N).
You should output the numbers of soldiers as they leave the circle. The numbers should be separated by single spaces.
3 1 5 2 4
Problem Author: Ilya Grebnov, Nikita Rybak, Dmitry Kovalioff
Problem Source: Timus Top Coders: Third Challenge