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

Shuriken Game

Shuriken Game

\includegraphics{https://static.e-olymp.com/content/33/3339fc512fbb9cba152df3e27c33480b29c099cd.jpg} Being a ninja means spending a lot of time training. To pass the time between training sessions, ninjas like to play games with their shurikens^1. An old favorite of the ninjas is a game for two players featuring one stack of shurikens. In turn, each player takes a number of shurikens from the stack, at least one but at most N. The winner is the player to take the last shuriken(s). It took a while, but every ninja eventually discovered what strategy you have to follow in order to win, and the ninjas lost interest in the game. Fortunately, one ninja came up with an additional rule that would hopefully make the game non-trivial again. This extra rule is that a player is not allowed to copy his opponent's last move, i.e. remove the same number of shurikens as his opponent just did. If the stack consists of just one shuriken, and the other player has just taken one, the player to move has no legal move and loses. Can you help the ninjas figure out how the player to move can win in a given game situation? ________________ ^1 - A shuriken is a metal star with sharp corners which ninjas use to throw at enemies. \InputFile The first line of the input contains a single number: the number of test cases to follow. Each test case has the following format: \begin{itemize} \item One line with three integers \textbf{S}, \textbf{N} and \textbf{P}, satisfying \textbf{1} ≤ \textbf{S} ≤ \textbf{100000}, \textbf{2} ≤ \textbf{N} ≤ \textbf{100} and \textbf{1} ≤ \textbf{P} ≤ \textbf{N}: the number of shurikens in the stack, the maximum number of shurikens a player is allowed to take from the stack, and the last move from the other player, respectively. \end{itemize} \OutputFile For every test case in the input, the output should contain one integer on a single line: the smallest amount of shurikens that the player to move can take in order to secure the win. If there is no winning move, the output should be\textbf{0}.
Лимит времени 3 секунды
Лимит использования памяти 64 MiB
Входные данные #1
5
12 4 1
5 5 5
6 6 6
100 5 5
100 5 1
Выходные данные #1
2
0
3
1
2