Canadian Computing Competition: 1998 Stage 2, Day 2, Problem 3
There once were two sad people who were named, oddly enough, and . They were sad because they were always being talked about, often quite slanderously, in math problems by the callous, faceless mathematical institution. Whenever they would talk to other people, the mean people would say "Hey, I read about you! You're always collecting and losing apples, aren't you?" They could not get jobs, because the mean interviewers would say "Didn't I read that at one point you two were prisoners? Hmmm, this is a dilemma…"
While the author feels deeply for them, unfortunately, he lacks any semblance of an imagination and none of the other letters could make it, so he will be using them yet again. However, to prevent the standard misconceptions, please read the disclaimer.
and are playing a game. They have tokens, inscribed with the numbers to . takes token and places it in one of two piles. then takes token and places it in one of the two piles. does this with token , and so on, until the last player places token in one of the two piles.
The numbers on the tokens in each of the piles are summed up, and wins if the two totals are relatively prime. (Two numbers are relatively prime if there is no integer greater than which evenly divides both of them) Otherwise, wins. (Note: an empty pile has total , and every integer evenly divides )
Your goal is to figure out, if both and play perfectly, which one of them will win for a given .
Note: This question is for the sole purpose of cruelty to participants of the CCC. Any resemblance to real or imagined persons, living or dead, is purely coincidental.
Input Specification
Several lines containing the number of tokens for different games to be analyzed. Each line consists of a single number , , except for the last line, which contains the number .
Output Specification
For each non-zero , you are to print out who will win the game ( or ) with tokens, assuming both play as well as possible.
Sample Input
2
5
10
0
Sample Output
When n=2, B will win.
When n=5, A will win.
When n=10, A will win.
Comments