CF850C Arpa and a game with Mojtaba

一、题目

点此看题

二、解法

考虑 SG \text{SG} SG函数的解法。

由于不同质数的博弈是相互独立的,我们可以把原问题分解成对于每一个素数博弈的子问题,答案就是这些子问题的 SG \text{SG} SG函数异或和。

考虑每个素数的博弈,由于原操作是批量消去素数的指数,我们只需要知道那些指数出现过,把它状压起来,当作 SG \text{SG} SG函数的下标,转移就枚举消去指数的大小 k k k,数组都开成 m a p map map就可以了。

这种做法的复杂度我算不出来,但感性理解,转移就是把高位的一段填到低位去,由此生成的状态一定不会太大,原谅我只能口胡 ,然后就贴个我的 AC \text{AC} AC代码。

#include <cstdio>
#include <map>
using namespace std;
int read()
{
    int x=0,flag=1;char c;
    while((c=getchar())<'0' || c>'9') if(c=='-') flag=-1;
    while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x*flag;
}
map<int,int> st,sg;
void fuck(int x)
{
    for(int i=2;i*i<=x;i++)
    {
        int t=0;
        while(x%i==0)
        {
            t++;
            x/=i;
        }
        if(t) st[i]|=1<<(t-1);
    }
    if(x>1) st[x]|=1;
}
int get(int x)
{
    if(x==0) return 0;
    if(sg.count(x)) return sg[x];
    map<int,int> vis;
    int p=x,k=0;
    while(p) p>>=1,k++;
    for(int i=1;i<=k;i++)
        vis[get((x>>i)|(x&((1<<i-1)-1)))]=1;
    for(int i=0;;i++)
        if(!vis[i])
            return sg[x]=i;
}
int main()
{
    int n=read(),flag=0;
    for(int i=1;i<=n;i++)
        fuck(read());
    map<int,int> :: iterator it = st.begin();
    for(;it!=st.end();it++) flag^=get(it->second);
    if(flag) puts("Mojtaba");
    else puts("Arpa");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值