spoj#CHGROOM. Room Change
Room Change
Problem Statement
It's the end of the semester and best friends Anne and Marian have finally gotten permission from the hostel supervisor to swap rooms and become room mates. Both of them are extremely happy to hear this, but one problem still remains. Although Anne and Marian definitely want to be room mates, both of them are also very attached to their current rooms and neither of them wants to move out.
After a lot of discussion regarding who should be the one to shift rooms, they decide to settle the matter in the following manner :
Both Anne and Marian write down, independently, 2 positive integers k1 and k2. Then, the value q = ( k1 + k2 - 1 ) is written down on a piece of a paper. Anne is the first person to make a move. During each move, the current player writes down any integer number that is a non-trivial divisor of the last written number. The first person who can't make a move wins, and the other person is the one who needs to shift into the winner's room.
Given that both players play optimally, output the name of the person who wins the game for a given value of q.
NOTE : A number's divisor is said to be non-trivial if it is different from one and from the divided number itself.
Input
The input contains a single integer q ( 1 <= q <= 1013 ).
Output
On a single line output "ANNE" if Anne wins. Else output "MARIAN". Note that the quotes are just for clarity, and that the output is case-sensitive.
Example
Input #1:
6
Output #1:
MARIAN
Input #2:
30
Output #2:
ANNE
Input #3:
1
Output #3:
ANNEExplanation :
Input #1 : 6 has exactly 2 non-trivial divisors - { 2, 3 }. But neither of these numbers have any non-trivial divisors. So no matter which one Anne writes down, Marian will win since she cannot make any move
Input #2 : Since 6 is a non-trivial divisor of 30, Anne writes down 6. Now, as can be seen from input #1, no matter what move Marian makes, Anne will win.
Input #3 : Since 1 has no non-trivial divisors, Anne wins.