Red Chips, Green Chips
Time limit1sMemory limit128 MB
With r red and g green chips, players alternately remove k chips of one color where k divides the other color's count; decide the winner under optimal play.
- Level
Hard8 of 10
- Topics
- Game theory, Math, Number theory, Implementation
- Solved
- No attempts yet
Problem
There are red chips and green chips on a desk. Two players, A and B, take turns, with A moving first.
On your turn, you do the following:
- Choose one of the two colors, red or green.
- Remove chips of the chosen color from the desk. Here must be a positive integer that divides the number of chips of the other (not chosen) color, and it cannot exceed the number of chips remaining in the chosen color.
The player who removes the last chip wins.
Assuming both players play optimally, write a program that determines who always wins.
Input
The first line contains two integers and separated by a space. ()
Output
Print A player wins if A can always win, or B player wins if B can always win.