Dungeons Game
문제
Robert is designing a new computer game. The game involves one hero, opponents and dungeons. The opponents are numbered from to and the dungeons are numbered from to . Opponent () is located in dungeon and has strength . There is no opponent in dungeon .
The hero starts off entering dungeon , with strength . Every time the hero enters any dungeon (), they confront opponent , and one of the following occurs:
- If the hero's strength is greater than or equal to the opponent's strength , the hero wins. This causes the hero's strength to increase by (). In this case the hero enters dungeon next ().
- Otherwise, the hero loses. This causes the hero's strength to increase by (). In this case the hero enters dungeon next.
Note may be less than, equal to, or greater than . Also, may be less than, equal to, or greater than . Regardless of the outcome of the confrontation, the opponent remains in dungeon and maintains strength .
The game ends when the hero enters dungeon . One can show that the game ends after a finite number of confrontations, regardless of the hero's starting dungeon and strength.
Robert asked you to test his game by running simulations. For each simulation, Robert defines a starting dungeon and starting strength . Your task is to find out, for each simulation, the hero's strength when the game ends.