Apples and Bananas
Time limit1sMemory limit128 MB
Decide the winner of an alternating game where each move removes one apple, one banana, three apples and one banana, or one apple and three bananas from piles of a apples and b bananas.
- Level
Medium7 of 10
- Topics
- Game theory, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Alice and Bob play a game with a pile of apples and bananas. Alice moves first, and the two alternate turns. On a turn a player removes exactly one of the following combinations: apple, banana, apples and banana, or apple and bananas. A move is legal only when the pile holds at least that many of each fruit. The player who removes the last fruit wins. When the pile starts empty, Bob wins at once. Given the numbers of apples and bananas and optimal play from both sides, decide whether Alice or Bob wins.
Input
The input holds the apple count and the banana count , separated by a space. Both satisfy .
Output
Print the name of the winner under optimal play, either Alice or Bob.