eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Musical Chairs

Musical Chairs

\includegraphics{https://static.e-olymp.com/content/76/76c9be8a80272282ff7ee80996ef37e019562ccc.jpg} In the traditional game of Musical Chairs, \textbf{N}+\textbf{1} children run around \textbf{N} chairs (placed in a circle) as long as music is playing. The moment the music stops, children run and try to sit on an available chair. The child still standing leaves the game, a chair is removed, and the game continues with \textbf{N} children. The last child to sit is the winner. In an attempt to create a similar game on these days' game consoles, you modify the game in the following manner: \textbf{N} Children are seated on \textbf{N} chairs arranged around a circle. The chairs are numbered from \textbf{1} to \textbf{N}. Your program pre-selects a positive number \textbf{D}. The program starts going in circles counting the children starting with the first chair. Once the count reaches \textbf{D}, that child leaves the game, removing his/her chair. The program starts counting again, beginning with the next chair in the circle. The last child remaining in the circle is the winner. For example, consider the game illustrated in the figure above for \textbf{N} = \textbf{5} and \textbf{D} = \textbf{3}. In the figure, the dot indicates where counting starts and \textbf{×} indicates the child leaving. Starting off, child \textbf{#3} leaves the game, and counting restarts with child \textbf{#4}. Child \textbf{#1} is the second child to leave and counting restart with child \textbf{#2} resulting in child \textbf{#5} leaving. Child \textbf{#2} is the last to leave, and child \textbf{#4} is the winner. Write a program to determine the winning child given both \textbf{N} and \textbf{D}. \InputFile Your program will be tested on one or more test cases. Each test case specifies two positive integers \textbf{N} and \textbf{D} on a single line, separated by one or more spaces, where \textbf{N}, \textbf{D} < \textbf{1000000}. The last line of the input file contains two \textbf{0}'s and is not part of the test cases. \OutputFile For each test case, write the winner using the following format: \textbf{N D W} Where \textbf{N} and \textbf{D} are as above, is a space character, and \textbf{W} is the winner of that game.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
5 3
7 4
0 0
Вихідні дані #1
5 3 4
7 4 2