E. Arpa and a game with Mojtaba time limit per test 1 second memory limit per test, megabytes input standard input OUTP UT standard output
Mojtaba and Arpa are playing a game. They has a list of n numbers in the game.
In a player's turn, he chooses a number PK (where p is a prime number and K are a positive integer) such that PK divides at least one number in the list. For each number in the list divisible by PK, call it X, the player would delete X and add to the list. The player can not make a valid choice of P and K loses.
Mojtaba starts the game and the players alternatively make moves. Determine which one of players'll be the winner if both players play optimally. Input
The first line contains a single integer n (1≤n≤100)-the number of elements in the list.
The second line contains n integers a1, a2, ..., an (1≤ai≤109)-the elements of the list. Output
If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes).
You can print each letter in any case (upper or lower). Examples input
4
1 1) 1 1
Output
Arpa
Input
4
1 1) 17 17
Output
Mojtaba
Input
4
1 1) 17 289
Output
Arpa
Input
5
1 2 3 4 5
Output
Arpa
Note
In the first sample test, Mojtaba can ' t move.
In the second sample test, Mojtaba chooses P = + and k = 1, then the list changes to [1, 1, 1, 1].
In the third sample test, if Mojtaba chooses P = + and k = 1, then Arpa chooses p = and k = 1 and wins, if Mojtaba Cho OSes p = + and k = 2, then Arpa chooses p = + k = 1 and WINS.
Game problem. There are many numbers, each time each person can choose a prime number of K-side, the choice must be selected by a number of numbers in the factor, after the election, all the numbers that have this factor in the sequence divided by this number. At last there are no optional numbers to lose.
Obviously for each prime number, can choose the situation is independent of each other, so you can first divide the sequence into several sub-sequences, each sub-sequence of numbers is either 1, or a multiple of a prime. Each operation can be considered as one of the subsequence operations. Such a final general game situation can be the sub-game of the SG value XOR.
For a fixed prime number p, its k-th square no matter how many, produces the same game effect. Therefore, you can compress all the numbers into a binary number, and the I-bit is 1 to indicate that the p^k exists in the sequence. Since the number does not exceed 2^30, the last compressed number will not exceed int.
Set the current state to Q, each operation divided by P^k, the equivalent of the state after the K-bit to move the whole K-bit to the right, the previous number of digits unchanged. In other words, the status Q becomes (q>>k) | (q& (1<< (k-1)-1)). The SG function can be calculated based on these violence.
#include <cstdio> #include <iostream> #include <string.h> #include <string> #include <map > #include <queue> #include <vector> #include <set> #include <algorithm> #include <math.h&
Gt #include <cmath> #include <stack> #define MEM0 (a) memset (A,0,sizeof (a)) #define Meminf (a) memset (a,0x3f,
sizeof (a)) #define N 32000 using namespace std;
typedef long Long LL;
typedef long double LD;
typedef double DB;
const int maxn=105,inf=0x3f3f3f3f;
const LL LLINF=0X3F3F3F3F3F3F3F3F;
Const LD Pi=acos ( -1.0L);
int A[N],B[MAXN];
BOOL Prime[n];
int num;
map<int,int> SG;
void Init () {num=0;
MEM0 (prime);
int i,j;
for (i=2;i<=n;i++) {if (!prime[i]) a[++num]=i;
for (j=1;j<=num&&i*a[j]<=n;j++) {prime[i*a[j]]=1;
if (i%a[j]==0) break;
}}} int getsg (int state) {if (state==0) return 0;
if (Sg[state]) return sg[state];
int i;
BOOL visit[100];
MEM0 (visit); for (i=1;i<=31&&(state>>i-1) >0;i++) VISIT[GETSG ((state>>i) | (
state& ((1<<i-1)-1))]=1; for (i=0;;
i++) if (!visit[i]) return sg[state]=i;
} int main () {init ();
int n,i,j,x,state,y=-1;
scanf ("%d", &n);
for (i=1;i<=n;i++) {scanf ("%d", &b[i]);
Y=max (Y,b[i]);
} int sum=0;
for (i=1;i<=num&&a[i]*a[i]<=y;i++) {state=0;
for (j=1;j<=n;j++) {int cnt=0;
while (b[j]%a[i]==0) {cnt++;
B[j]/=a[i]; } if (CNT) state=state|
(1<<cnt-1);
} SUM=SUM^GETSG (state);
} for (i=1;i<=n;i++) {if (b[i]==1) continue;
SUM=SUM^GETSG (1);
int p=b[i];
for (j=1;j<=n;j++) while (b[j]%p==0) b[j]/=p; } if (sum) cout << "Mojtaba";
else cout << "Arpa";
return 0;
}