Multiplication Game
Time limit5sMemory limit512 MB
Given N, players alternate multiplying a running product by a prime factor of N; making it equal N wins, overshooting ties.
- Level
Medium7 of 10
- Topics
- Game theory, Number theory, Math, Brute force
- Solved
- No attempts yet
Problem
Alice and Bob are working through multiplication and division drills in class. They get bored fast, so they invent a game instead.
The game starts with a target integer () and an integer . Alice and Bob take alternate turns. On a turn the player picks a prime divisor of and multiplies by . If the move makes equal to the target , the player who made it wins. If the move makes greater than , the game ends in a tie right there.
Both players play optimally. Work out who wins, if anyone.
Input
The first line contains (), the number of cases. Each of the next lines holds one case: the target integer () followed by the name of the player taking the first turn, separated by a space. The name is either Alice or Bob.
Output
For each case print the name of the winner under optimal play, Alice or Bob, on its own line. Print tie if neither player wins.