题目大意:
  给你一个包含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. 在Unity中实现屏幕空间阴影(2)

    参考文章: https://www.imgtec.com/blog/implementing-fast-ray-traced-soft-shadows-in-a-game-engine/ 完成的工程: ...

  2. 2017ACM暑期多校联合训练 - Team 8 1006 HDU 6138 Fleet of the Eternal Throne (字符串处理 AC自动机)

    题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion ...

  3. NYOJ 739 笨蛋难题四 (数学)

    题目链接 描述 这些日子笨蛋一直研究股票,经过调研,终于发现xxx公司股票规律,更可喜的是 笨蛋推算出这家公司每天的股价,为了防止别人发现他的秘密.他决定对于这家公司的 股票最多买一次,现在笨蛋已经将 ...

  4. PHP非常好用的分页类

    分页类: <?php /* * ********************************************* * @类名: page * @参数: $myde_total - 总记 ...

  5. docker 镜像导入和导出

    使用 docker commit 即可把这个容器变为一个镜像 docker commit 8d93082a9ce1 ubuntu:myubuntu 这时候 docker 容器会被创建为一个新的 Ubu ...

  6. angular 最大字数限制

    js可以通过onkeyup onkeydown判断当前节点字数. angular可以通过监听的方式: $scope.input = {//初始化,避免ng-model绑定取不到值 MaxBT:'', ...

  7. 安装ssh-keygen

    转载自:http://www.daoan.com/forums/index.php?forumid=5&mods=topicdisplay&postid=4 sudo apt-get ...

  8. Petrozavodsk Winter Training Camp 2018

    Petrozavodsk Winter Training Camp 2018 Problem A. Mines 题目描述:有\(n\)个炸弹放在\(x\)轴上,第\(i\)个位置为\(p_i\),爆炸 ...

  9. openjudge-NOI 2.6-1944 吃糖果

    题目链接:http://noi.openjudge.cn/ch0206/1944/ 题解: 递推,题目中给出了很详细的过程,不讲解 #include<cstdio> int n; int ...

  10. 修改vs17中的cordova模板

    因为visual studio 2017创建的默认cordova-ios的版本自动编译带有swift语言的插件会出现异常,cordova-ios升级到4.3.1,并且配置build.json能解决问题 ...