Round Robin
InterviewTime limit1sMemory limit128 MB
Simulate rounds of T turns around the circle, remove the player who takes the last turn, and report the survivors and their shared count when the rest tie.
- Level
Easy3 of 10
- Topics
- Simulation
- Solved
- No attempts yet
Problem
players sit in a fixed order and take turns one at a time. The first player follows the last one, so turns keep going around the circle. Every player counts the turns he or she has taken.
The game runs in rounds. One round consists of exactly turns, and when a round ends, the player who just took a turn leaves the game. If every remaining player has the same count at that moment, the game is over. Otherwise a new round of turns starts with the player immediately after the one who just left.
When a single player remains, there is nobody to compare with, so the counts are treated as equal and the game is over.
Here is how a game with and plays out. Label the players A, B, C, D and E in order, with every count starting at zero.
Starting with A, 17 turns are taken. B takes the last of them.
B leaves the game, and the next turn goes to C.
After 17 more turns starting with C, players A, D and E gain 4 turns each, while C gains 5 including the last one.
C leaves. The remaining counts are not all equal, so a new round begins with D.
The 17 turns starting with D end with E. A gains 5 turns, D and E gain 6 each.
Then E leaves.
The two remaining players both have a count of 13, so the game ends. E's count does not enter that decision.
Input
The input contains one or more datasets. Each dataset is a single line holding two integers and separated by a space. () is the initial number of players, and () is the number of turns taken in one round. The line after the last dataset contains only .
Output
For each dataset print one line with two integers and separated by a space. At the moment the game ends, is the number of players still in the game and is the count they all share.