Hitachi Vantara Programming Contest 2024(AtCoder Beginner Contest 368)F - Dividing Game

昊天djh發表於2024-08-28

https://atcoder.jp/contests/abc368/tasks/abc368_f

#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair<ll,char> pii;
const int N=2e5+10,inf=1e9;
ll n,m,k;
int b[N],sg[N],a[N];
vector<int> divi[N];//divi[i]為小於i的所有因子
void init()
{
    for(int i=1;i<N;i++)
        for(int j=2*i;j<N;j+=i)
            divi[j].push_back(i);

    sg[1]=0;
    for(int i=2;i<N;i++)
    {
        for(auto x:divi[i])
            b[sg[x]]=1;
        while(b[sg[i]]) sg[i]++;
        for(auto x:divi[i])
            b[sg[x]]=0;
    }
}
void solve()
{
    init();
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        res^=sg[a[i]];
    }
    if(res) puts("Anna");
    else puts("Bruno");
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int _=1;
    //cin>>_;
    while(_--)
    {
        solve();
    }

    return 0;
}

相關文章