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 ...
随机推荐
- 系统右键添加cmd命令
我们运行cmd.exe时,会发现刚刚打开时,一般提示在默认路径下: 有时候我们希望直接能够切换到某个路径下运行程序或者做某些工作,那么切换路径可能就会比较麻烦.下面我们介绍一种比较实用的方法,用鼠标右 ...
- 20162308 实验一《Java开发环境的熟悉》实验报告
a 20162308 实验一<Java开发环境的熟悉>实验报告 实验内容 使用JDK编译.运行简单的Java程序. 使用IDEA 编辑.编译.运行.调试Java程序. 实验要求 没有Lin ...
- Beta冲刺Day2
项目进展 李明皇 今天解决的进度 优化了信息详情页的布局:日期显示,添加举报按钮等 优化了程序的数据传递逻辑 明天安排 程序运行逻辑的完善 林翔 今天解决的进度 实现微信端消息发布的插入数据库 明天安 ...
- Flask 扩展 HTTP认证
Restful API不保存状态,无法依赖Cookie及Session来保存用户信息,自然也无法使用Flask-Login扩展来实现用户认证.所以这里,我们就要介绍另一个扩展,Flask-HTTPAu ...
- Flask Session 详解
会话session ,允许你在不同请求 之间储存信息.这个对象相当于用密钥签名加密的 cookie ,即用户可以查看你的 cookie ,但是如果没有密钥就无法修改它. from flask impo ...
- C语言头文件引用
1,引用分为两种 firs:include<fileName.h> 引用系统头文件一般用<>. second:include"fileName.h" 引用自 ...
- Python内置函数(55)——globals
英文文档: globals() Return a dictionary representing the current global symbol table. This is always the ...
- Python内置函数(27)——range
英文文档: range(stop) range(start, stop[, step]) Rather than being a function, range is actually an immu ...
- 阿里云API网关(11)外网访问 阿里云API网关内定义的API步骤:
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- 新概念英语(1-51)A pleasant climate
新概念英语(1-51)A pleasant climate Does it ever snow in Greece? A:Where do you come from? B:I come from G ...