Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba

时间:2023-03-09 10:04:00
Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba

首先容易想到,每种素数是独立的,相互sg就行了
对于一种素数来说,按照的朴素的mex没法做。。。
所以题解的简化就是数位化
多个数同时含有的满参数因子pk由于在博弈中一同变化的,让他们等于相当于2k,那么这样就是一个数了

之后就是模拟,牛逼的思路

#include<iostream>
#include<map>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
#define MS(x,y) memset(x,y,sizeof(x))
#define MP(x, y) make_pair(x, y)
const int INF = 0x3f3f3f3f; int prime[N];
int isprime[N]; int tot = 0;
int n;
map<int, int> mp;
map<int, int> dp;
map<int, int> ::iterator it; int solve(int x){
if(dp.find(x) != dp.end()) return dp[x];
int mex[35];
MS(mex, 0);
for(int i = 0; x >> i; ++i) {
int tt = solve( (x >> (i + 1)) | ( ((1<<i) - 1) & x ) );
mex[tt] ++;
} for(int i = 0; i < 35; ++i) {
if(!mex[i]) {
dp[x] = i;
return i;
}
}
}
int main() {
for(int i = 2; i < N; ++i) {
if(isprime[i] == 0) {
prime[++tot] = i;
for(int j = 2*i; j < N; j += i) {
isprime[j] ++;
}
}
}
while(~scanf("%d", &n)) {
mp.clear(); for(int i = 0; i < n; ++i) {
int a; scanf("%d", &a);
for(int j = 1; j <= tot; ++j) {
if(a % prime[j] == 0) {
int cnt = 0;
while(a % prime[j] == 0) a /= prime[j], cnt ++;
mp[prime[j]] |= 1<<(cnt-1);
if(a == 1) break;
}
}
if(a != 1) {
mp[a] |= 1;
}
} int ans = 0;
for(it = mp.begin(); it != mp.end(); ++it) {
dp.clear();
ans ^= solve(it -> second);
}
if(ans) printf("Mojtaba\n");
else printf("Arpa\n");
}
return 0;
}