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

思路:
  显然,结果不直接与数列中数的值有关,而与数列中每个数的质因数及其次数有关,因此我们可以将每个质因数分开考虑。
  枚举数列中出现的每一个质因数p,对数列中的数除去p^k就相当于将p对应的次数减去k。
  如果不同的数对于同一个质因数p,对应的次数相同,那么无论除去p的几次,对于这两个数的影响都是一样的。
  那么我们只需要将不同的质数作为我们的子游戏,游戏状态记录p出现次数(即,如果一个数中包含17,一个数中包含17^2,那么就记录1和2)。
  极限情况,2^31>1e9,那么对于每一个质数,我们可以用一个int类型状压记录出现次数。
  即,若状态s的第i位为1,则p^i在数列中出现。
  求SG函数的时候,我们可以发现SG函数的取值仅与出现次数,即状态s有关,而与具体是哪个质数无关。
  我们可以从s的最高位枚举,依次考虑把s在i后面的位数减掉的情况,这样,较高的次数在降次以后会加到较低的位数,这一操作可以用位运算(x%si)|(x/si)表示。
  对于边界情况,s=1时,表示数列中已经没有这样的质因数,SG值显然是0。

 #include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<cstring>
#include<ext/hash_map>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int N=;
__gnu_cxx::hash_map<int,int> sg;
int a[N];
inline int count(int &x,const int &p) {
int ret=;
while(!(x%p)) {
ret++;
x/=p;
}
return ret;
}
int getsg(const int x) {
if(sg.count(x)) {
return sg[x];
}
if(x==) return sg[x]=;
int si=<<;
while(!(x&si)) si>>=;
int mex[];
memset(mex,,sizeof mex);
while(si!=) {
mex[getsg((x%si)|(x/si))]=x;
si>>=;
}
int tmp=;
while(mex[tmp]==x) tmp++;
return sg[x]=tmp;
}
int main() {
int n=getint();
for(int i=;i<n;i++) {
a[i]=getint();
}
int ans=;
for(int i=;i<n;i++) {
int tmp=a[i];
for(int j=;j<=sqrt(tmp);j++) {
if(!(tmp%j)) {
int s=;
for(int k=;k<n;k++) {
s|=<<count(a[k],j);
}
ans^=getsg(s);
}
}
if(a[i]!=) {
int p=a[i];
int s=;
for(int k=;k<n;k++) {
s|=<<count(a[k],p);
}
ans^=getsg(s);
}
}
puts(ans?"Mojtaba":"Arpa");
return ;
}

[CodeForces850C]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 Round #432 Div. 1 C. Arpa and a game with Mojtaba

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

  3. Codefroces 850C Arpa and a game with Mojtaba

    Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的 ...

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

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

  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. 2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)

    题目链接 Problem Description The school set up three elective courses, assuming that these courses are A ...

  2. JS 检测客户端断网情况

    常用方法 1 navigator.onLine 2 window.addEventListener() 3 获取网络资源 4 ajax请求 1. navigator.onLine 只会在机器未连上路由 ...

  3. weblogic 配置了ssl

    jingyan.baidu.com/article/72ee561abfe531e16138dfb5.html http://blog.sina.com.cn/s/blog_7ffec3e201019 ...

  4. webconfig的配置解析

    <?xml version="1.0"?> <!--注意: 除了手动编辑此文件以外,您还可以使用 Web 管理工具来配置应用程序的设置.可以使用 Visual S ...

  5. 一个TCP报文段的数据部分最多为多少个字节,为什么

    IP数据报的最大长度=2^16-1=65535(字节)TCP报文段的数据部分=IP数据报的最大长度-IP数据报的首部-TCP报文段的首部=65535-20-20=65495(字节) 一个tcp报文段的 ...

  6. The algorithm of entropy realization

    近似熵的一种快速实用算法 Pincus提出的近似熵算法中有很多冗余的计算,效率低,速度慢,不利于实际应用,洪波等人在定义的基础上引入二值距离矩阵的概率,提出了一种实用快速的算法. function A ...

  7. oracle客户端不需要配置tnsnames.ora文件直接连接服务器数据库

    在以前的oracle使用过程中,想要在客户端连接到服务器时,都是在客户端中的tnsnames.ora文件配置如以下内容: adb = (DESCRIPTION = (ADDRESS_LIST = (A ...

  8. What does “=>” mean in import in scala?(转自StackOverflow问答)

      As others have mentioned, it's an import rename. There is however one further feature that proves ...

  9. python 面试

    知识总结 面试(一)

  10. logstash参数配置

    input配置: file:读取文件 input { file{ path => ["/var/log/*.log","/var/log/message" ...