Box Splitting Game
Time limit2sMemory limit512 MB
Decide whether the first or second player wins the two-box stone-splitting game from starting counts N and M.
- Level
Medium4 of 10
- Topics
- Game theory, Dynamic programming
- Solved
- No attempts yet
Problem
The box splitting game is played with two boxes.
At the start one box holds stones and the other holds stones. Two players take turns.
On your turn you choose one box and empty it completely. You then take the stones sitting in the other box and put them into the two boxes. Each of the two boxes must hold at least 1 stone afterwards.
The player who leaves exactly 1 stone in each box wins the game.
Given and , write a program that finds the winner when both players play the game perfectly.
Input
The first line contains and , separated by a space. (, and and are never both 1.)
Output
Print A if the player who starts the game wins, and B if the player who moves second wins.