题目大意:
  给你一个包含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. styled-components真的好吗?

    最近在学习react,然后遇到react中css该怎么写这个问题,上知乎上看了好多大牛都说styled-components好用是大势所趋. 但我自己用了感觉体验却很差,我在这里说说我为啥觉得styl ...

  2. Javascript装饰器的妙用

    最近新开了一个Node项目,采用TypeScript来开发,在数据库及路由管理方面用了不少的装饰器,发觉这的确是一个好东西.装饰器是一个还处于草案中的特性,目前木有直接支持该语法的环境,但是可以通过 ...

  3. Verilog笔记.6.FIFO

    FIFO,First In First Out ,是一种先进先出的数据缓存器. 没有外部读写地址线,只能顺序写入数据,顺序的读出数据, 其数据地址由内部读写指针自动加1完成. 不能像普通存储器那样可以 ...

  4. es6新语法Object.assign()

    1.介绍 Object.assign用于对象的合并,将源对象的所有可枚举属性复制到目标对象,只拷贝源对象自身的属性继承属性补考呗 Object.assign(target,source1,...)第一 ...

  5. 2013-7-31hibernate二级缓存

    难得闲 Fckeditor Fckconfig.js大部分配置都在这里面, 增加字体:         程序代码: FCKConfig.FontNames = 'Arial;Comic Sans MS ...

  6. 【转载】在GitHub上管理项目

    在GitHub上管理项目 新建repository 本地目录下,在命令行里新建一个代码仓库(repository) 里面只有一个README.md 命令如下: touch README.md git ...

  7. 简单优化:Zipalign

    Android SDK中包含一个“zipalign”的工具,它能够对打包的应用程序进行优化.在你的应用程序上运行zipalign,使得在运行时Android与应用程序间的交互更加有效率.因此,这种方式 ...

  8. Adding Completion to (interactive)

      Adding Completion to (interactive) Author: Tubo Question: Is there any way to add my own completio ...

  9. 摄像机distortion vector、project matrix、camera matrix

    关于标定后图像如何校正:http://wiki.ros.org/image_pipeline/CameraInfo ros distortion vector 参数顺序:http://docs.ros ...

  10. java-list-分组

    Map<String, List<Hb12Domain>> groupBy = hb18DomainList.stream().collect(Collectors.group ...