Topic: Give you n numbers, a1, a2,... An, two people take turns to change the number from it. Each time they choose a prime p and a positive integer k, divide all the numbers from A1 to an that can be divisible by p^k by p^k. When the player changes all the numbers to one in his turn, the player wins.
Thought: Because p can only be prime, so we can decompose a1 to an into prime factors. Different prime numbers do not affect each other, for example, 2, 3, 4, 6. If I choose 2 for p and 1 for k, I will become 1, 3, 2, 3. It has no effect on p 3. So we just need to calculate the SG value of each prime number and then XOR is the answer.
Next, we need to solve how to get SG value for a single prime. First, we need to deal with the arrays from a1 to an because only the current arrays of prime numbers are present. For example, 2, 3, 4, 6, when p=2, we treat it as 2 ^ 1, 2 ^ 0, 2 ^ 2, 2 ^ 1, that is, 1, 0, 2, 1, because all the integers from a1 to an that can be divided by p^k are divided by p^k, so we can consider the same number of factors p as a number. So when i choose 2 ^ 1, 1, 0, 2, 1 becomes 0, 0, 1, 0. The changes of these two 1 are the same at any time, so the two 1 can be regarded as one. So we can define a state according to this point: state is true in the first place, if and only if there is a number equal to p^i in the current state. For example, the state value of 1, 0, 2, 1 is equal to 1 + 2 = 3. The state values of 1, 2, 2, 3, 3, 5 are equal to 1 + 2 + 4 + 16 = 23.
For each state, to enumerate K from 1 to its maximum number of digits, for each k, the number of digits larger than or equal to k, it must be reduced by K (dividing all the digits from a1 to an that can be divided by p^k by p^k), such as 1, 2, 2, 3, 3, 5. When K is 3, the subsequent state is 1, 2, 2, 0, 2.
So (state > k) | (state & ((1 << k-1) - 1)) is the subsequent state of state.
Then the problem can be solved. It is important to use map to store the value of SG function.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9 + 5;
const int MAXN = 100007;
const int MOD = 30021;
const double eps = 1e-8;
const double PI = acos(-1.0);
map<int, int> SG,num;
int getSG(int x)
{
if (x == 0)
return 0;
if (SG.count(x))
return SG[x];
map<int, int> vis;
int p = x;
int t=0;
while (p)//Calculate the maximum number of digits
p /= 2,t++;
for (int k = 1; k <= t; k++)
vis[getSG((x >> k) | (x&((1 << k-1) - 1)))] = 1;//Follow-up status
for (int i = 0;; i++)
if (!vis[i])
return SG[x]=i;
}
int prime[MAXN], primesize;
bool isprime[MAXN];
void getlist(int listsize)//Primitive Number Tables
{
memset(isprime, 1, sizeof(isprime));
isprime[1] = false;
for (int i = 2; i <= listsize; i++)
{
if (isprime[i])prime[++primesize] = i;
for (int j = 1; j <= primesize&&i*prime[j] <= listsize; j++)
{
isprime[i*prime[j]] = false;
if (i%prime[j] == 0)break;
}
}
}
void solve()//Decomposition the read x prime factor
{
int t,x;
scanf("%d", &x);
for (int i = 1; prime[i]*prime[i] <= x; i++)
{
t = 0;
while (x%prime[i] == 0)
x /= prime[i], t++;//Calculating x is the power of p
if(t!=0)
num[prime[i]] = num[prime[i]] | 1 << (t - 1);//This number is equal to p^t, so t is true.
}
if (x != 1)
num[x] = num[x] | 1;
}
int main()
{
getlist(100005);
int n;
int x;
int ans = 0;
scanf("%d", &n);
while (n--)
solve();
map<int, int>::iterator it;
for (it = num.begin(); it != num.end(); it++)
ans ^= getSG(it->second);
if (ans == 0)
printf("Arpa\n");
else
printf("Mojtaba\n");
}