Codefroces 850C Arpa and a game with Mojtaba
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的更多相关文章
- Codeforces 850C Arpa and a game with Mojtaba
题意:给定一个正整数序列,两人轮流对这个数列进行如下修改:选取一个素数p和一个整数k将序列中能整除p^k的数除以p^k,问谁有必胜策略. 借此复习一下sg函数吧,sg(x) = mex ( sg(y) ...
- Codeforces 850C E. Arpa and a game with Mojtaba
对每个数统计其素数因子各次方数的数,然后通过y = (x>>i) | (x&((1<<(i-1))-1)) 模拟delete x and add to the lis ...
- Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba
首先容易想到,每种素数是独立的,相互sg就行了 对于一种素数来说,按照的朴素的mex没法做... 所以题解的简化就是数位化 多个数同时含有的满参数因子由于在博弈中一同变化的,让他们等于相当于,那么这样 ...
- [CodeForces850C]Arpa and a game with Mojtaba
题目大意: 给你一个包含n个数的数列,两个人轮流对数列进行如下操作: 选择一个质数p和一个正整数k,将数列中所有能被p^k整除的数除以p^k. 最后不能操作者负. 问先手是否有必胜策略. 思路: 显然 ...
- 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 ...
- 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 ...
- ARPA
ARPA是英文Advanced Research Projects Agency的缩写,代表美国国防部高级研究计划署.是美国国防部高级研究计划管理局因军事目的而建立的,开始时只连接了4台主机,这便是只 ...
- 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 ...
- 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 ...
随机推荐
- 团队开发---”我爱淘“校园二手书店 NABC分析
本项目特点之一:可预订 N:对于一些抢手的书可以提前预定,避免学生买不到书 A:网上下单,通过手机便捷购物 B:使得订书更加方便快捷 C:二手书摊.网上书店 团队成员:杨广鑫.郭健豪.李明.郑涛
- 2017-2018-1 1623 bug终结者 冲刺006
bug终结者 冲刺006 by 20162328 蔡文琛 今日任务:音频素材添加 又是新的一天,小组项目有了很大的起色,已经可以在手机上试玩了. 添加背景音乐能使我们的游戏锦上添花. 音频资源需求 需 ...
- Twisted 安全信道
1.安装python的SSL插件pyOpenSSL pip install pyopenssl 2.安装OpenSSL工具包 sudo apt-get install openssl sudo apt ...
- Spring+Hibernate+Struts(SSH)框架整合
SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...
- github提交代码到服务器的方法
第一种情况,没有冲突:1.git add .//进入到center的项目下将本地文件打包的意思2.git pull origin dev//将服务器的代码下载到本地如果是最新的会提示Already u ...
- Java XML Dom解析工具
Java XML Dom解析工具 缩进等 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ...
- Linq 生成运算符 Empty,Range,Repeat
var c1 = Enumerable.Empty<string>();//c1.Count=0 , );//{9527,9528,9529,......9536} , );//{9527 ...
- python RE模块的使用
摘要: re模块包括操作正则表达式的函数,一些工作中都需要用到,现在说明下使用方法. 使用说明: 一,re模块下的函数: 函数 描述 compile(pa ...
- Spring中报"Could not resolve placeholder"的解决方案
除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...
- spring-oauth-server实践:授权方式四:client_credentials 模式下access_token的产生
授权结果 获取access_token成功, 访问资源服务器API http://localhost:9000/api-gateway-engine/unity/user_info?access_to ...