Description
两个人Van♂游戏。给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数。接着将所有的$p^{k}$的倍数除以$p^{k}$。变成新的序列,继续操作。不能操作者为败,问先手是否必胜。
1≤100≤n,1≤ai≤109
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

不同质因数不互相影响

于是分开讨论每个质因数的SG值

压缩状态,如果一个数含有k个p

即$a[i]%p^{k}==0$

那么状态中第k-1位为1

那么枚举每一次的k,求出SG值

最后将每个质因数的答案取Nim和

不过状态可能会很大,用map

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
map<int,int>sg;
int n,a[],pri[],Max[],cnt,ans;
map<int,int>vis;
int qpow(int x,int y)
{
int res=;
while (y)
{
if (y&) res=res*x;
x=x*x;
y>>=;
}
return res;
}
int get_SG(int S)
{int i,p,SS,t;
if (sg.count(S)) return sg[S];
if (S==) return ;
map<int,int>v;
t=;SS=S;
while (SS)
{
SS>>=;
t++;
}
for (i=;i<t;i++)
{
p=i+,SS=S;
v[get_SG((SS>>p)|(((<<p-)-)&S))]=;
}
for (p=;;p++)
if (v.count(p)==) break;
return sg[S]=p;
}
int main()
{int i,j,tot,k;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%d",&a[i]);
int x=a[i],k=sqrt(x);
for (j=;j<=k;j++)
{tot=;
while (x%j==)
{
tot++;
if (vis[j]==) pri[++cnt]=j,vis[j]=cnt;
x/=j;
}
Max[vis[j]]=max(tot,Max[vis[j]]);
}
if (x!=)
{
if (vis[x]==) pri[++cnt]=x,vis[x]=cnt;
Max[vis[x]]=max(Max[vis[x]],);
}
}
ans=;
for (i=;i<=cnt;i++)
{
sg.clear();
int S=;
for (j=;j<=n;j++)
{
for (k=Max[i];k>=;k--)
{
if (a[j]%qpow(pri[i],k)==)
{
S|=(<<k-);
break;
}
}
}
ans^=get_SG(S);
}
if (ans==) printf("Arpa\n");
else printf("Mojtaba\n");
}

Codefroces 850C Arpa and a game with Mojtaba的更多相关文章

  1. Codeforces 850C Arpa and a game with Mojtaba

    题意:给定一个正整数序列,两人轮流对这个数列进行如下修改:选取一个素数p和一个整数k将序列中能整除p^k的数除以p^k,问谁有必胜策略. 借此复习一下sg函数吧,sg(x) = mex ( sg(y) ...

  2. Codeforces 850C E. Arpa and a game with Mojtaba

    对每个数统计其素数因子各次方数的数,然后通过y = (x>>i) | (x&((1<<(i-1))-1)) 模拟delete x and add  to the lis ...

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

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

  4. [CodeForces850C]Arpa and a game with Mojtaba

    题目大意: 给你一个包含n个数的数列,两个人轮流对数列进行如下操作: 选择一个质数p和一个正整数k,将数列中所有能被p^k整除的数除以p^k. 最后不能操作者负. 问先手是否有必胜策略. 思路: 显然 ...

  5. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  6. Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)

    D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...

  7. ARPA

    ARPA是英文Advanced Research Projects Agency的缩写,代表美国国防部高级研究计划署.是美国国防部高级研究计划管理局因军事目的而建立的,开始时只连接了4台主机,这便是只 ...

  8. Arpa's weak amphitheater and Mehrdad's valuable Hoses

    Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per ...

  9. Arpa's loud Owf and Mehrdad's evil plan

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

随机推荐

  1. 【R语言系列】作图入门示例一

    假设有如下数据,我们使用plot函数作图 月龄 体重 月龄 体重  1 4.4 9 7.3 3 5.3 3 6.0 5 7.2 9 10.4 2 5.2 12 10.2 11 8.5 3 6.1 R语 ...

  2. 【IntelliJ IDEA】使用idea解决新建jsp文件而找不到jsp文件模版的新建选项

    使用idea解决新建jsp文件而找不到jsp文件模版的新建选项,这样每次创建一个新的jsp文件岂不是很耗时间? 解决办法: 就是要让idea知道你需要在这个目录下创建jsp文件 左上角,file中点击 ...

  3. 网络1712--c语言一二维数组作业总结

    1.成绩摆前头 1.1基本要求(1分) 按时交 - 有分 未交 - 0分 迟交一周以上 - 倒扣本次作业分数 抄袭 - 0分 泛泛而谈(最多七分) 1.2评分要点 PTA作业总结(4分) 同学代码互评 ...

  4. Git使用方法2.0

    ## Git来源: 最早开始是由Ruby程序员们发起的.Ruby是日本的家伙搞出来的,日本有个代码托管网站叫heroku,当时用这个的人比较多,现在这个网站还能打开,网址是www.heroku.com ...

  5. PostgreSQL 配置安装

    Mac 安装 http://postgresapp.com/ 创建和删除数据库用户 对应命令如下(在postgres=# 环境下):1.查看数据库用户列表: \du2.创建数据库用户: create ...

  6. 201421123042 《Java程序设计》第14周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结与数据库相关内容. 答: 2. 使用数据库技术改造你的系统 2.1 简述如何使用数据库技术改造你的系统.要建立什么表?截图你的表设计 ...

  7. 构建微服务开发环境7————使用Github管理项目代码的版本

    [内容指引] 1.注册GitHub帐号: 2.下载Github Desktop客户端: 3.macOS安装Github Desktop客户端: 4.windows安装Github Desktop客户端 ...

  8. emqtt 试用(八)ssl认证 - 代码验证

    参考链接:http://emqtt.com/clients#java http://docs.emqtt.cn/zh_CN/latest/config.html#mqtt-ssl-8883 一.单向认 ...

  9. Mosquito集群模式

    参考链接: http://blog.csdn.net/z729685731/article/details/70142182 http://blog.csdn.net/yuhaiyang457288/ ...

  10. less初学手记

    less语言学习手记 工具下载 在less学习中,我们都会需要随时编译我们的less文件,查看生成的css样式表是否正确,以及是否符合我们的要求.推荐一款编译软件供大家下载使用:koala,本软件支持 ...