eolymp
bolt
Try our new interface for solving problems
Məsələlər

Round Robin

Round Robin

Suppose that \textbf{N} players sit in order and take turns in a game, with the first person following the last person, to continue in cyclic order. While doing so, each player keeps track of the number of turns he or she has taken. The game consists of rounds, and in each round \textbf{T} turns are taken. After a round, the player who just had a turn is eliminated from the game. If the remaining players have all had the same number of turns, the game ends. Otherwise, they continue with another round of \textbf{T} moves, starting with the player just after the one who was most recently eliminated. As an example, assume we begin a game with \textbf{N=5} and \textbf{T=17}, labeling the players in order as \textbf{A}, \textbf{B}, \textbf{C}, \textbf{D}, and \textbf{E}, with all counts initially zero. Beginning with \textbf{A}, \textbf{17} turns are taken. \textbf{B} will have taken the last of those turn, leaving our counts as follows: Suppose that after every \textbf{17} turns, the player who just had a turn is eliminated from the game. All remaining players then compare their counts. If all of those counts are equal, everyone has had a fair number of turns and the game is considered completed. Otherwise, they continue with another round of \textbf{17} moves starting with the player just after the one who was most recently eliminated. Continuing with our example, \textbf{B} will leave the game, and the next turn will be for \textbf{C}. After \textbf{17} more turns starting with \textbf{C}, we find that \textbf{A}, \textbf{D} and \textbf{E} received \textbf{4} turns, while \textbf{C} received \textbf{5} turns, including the last: Then \textbf{C} leaves, and since the remaining counts are not all the same, a new round beings with \textbf{D} having the next turn. The next \textbf{17} turns start with \textbf{D} and end with \textbf{E}. \textbf{A} adds \textbf{5} turns, while \textbf{D} and \textbf{E} add \textbf{6}: Then \textbf{E} leaves. At this point, notice that the two remaining players have the same count of \textbf{13}. Therefore, the game ends. (We note that \textbf{E}'s count was irrelevant to the decision to end the game.) \InputFile The input will contain one or more datasets. Each dataset will be described with a single line containing two integers, \textbf{N }and \textbf{T}, where \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{100}) is the initial number of players, and \textbf{T} (\textbf{2} ≤ \textbf{T} ≤ \textbf{100}) is the number of turns after which the player with the most recently completed turn leaves. Following the last dataset is a line containing only \textbf{0}. \OutputFile There is one line of output for each dataset, containing two numbers, \textbf{p} and \textbf{c}. At the time the game ends \textbf{p} is the number of players that remain in the game and \textbf{c} is the common count they all have.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
5 17 
7 10
90 2
0
Çıxış verilənləri #1
2 13
5 3
45 1
Mənbə ACM Mid-Central Regional Programming Contest 2013