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

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<map>
  7. using namespace std;
  8. map<int,int>sg;
  9. int n,a[],pri[],Max[],cnt,ans;
  10. map<int,int>vis;
  11. int qpow(int x,int y)
  12. {
  13. int res=;
  14. while (y)
  15. {
  16. if (y&) res=res*x;
  17. x=x*x;
  18. y>>=;
  19. }
  20. return res;
  21. }
  22. int get_SG(int S)
  23. {int i,p,SS,t;
  24. if (sg.count(S)) return sg[S];
  25. if (S==) return ;
  26. map<int,int>v;
  27. t=;SS=S;
  28. while (SS)
  29. {
  30. SS>>=;
  31. t++;
  32. }
  33. for (i=;i<t;i++)
  34. {
  35. p=i+,SS=S;
  36. v[get_SG((SS>>p)|(((<<p-)-)&S))]=;
  37. }
  38. for (p=;;p++)
  39. if (v.count(p)==) break;
  40. return sg[S]=p;
  41. }
  42. int main()
  43. {int i,j,tot,k;
  44. cin>>n;
  45. for (i=;i<=n;i++)
  46. {
  47. scanf("%d",&a[i]);
  48. int x=a[i],k=sqrt(x);
  49. for (j=;j<=k;j++)
  50. {tot=;
  51. while (x%j==)
  52. {
  53. tot++;
  54. if (vis[j]==) pri[++cnt]=j,vis[j]=cnt;
  55. x/=j;
  56. }
  57. Max[vis[j]]=max(tot,Max[vis[j]]);
  58. }
  59. if (x!=)
  60. {
  61. if (vis[x]==) pri[++cnt]=x,vis[x]=cnt;
  62. Max[vis[x]]=max(Max[vis[x]],);
  63. }
  64. }
  65. ans=;
  66. for (i=;i<=cnt;i++)
  67. {
  68. sg.clear();
  69. int S=;
  70. for (j=;j<=n;j++)
  71. {
  72. for (k=Max[i];k>=;k--)
  73. {
  74. if (a[j]%qpow(pri[i],k)==)
  75. {
  76. S|=(<<k-);
  77. break;
  78. }
  79. }
  80. }
  81. ans^=get_SG(S);
  82. }
  83. if (ans==) printf("Arpa\n");
  84. else printf("Mojtaba\n");
  85. }

Codefroces 850C 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 850C E. Arpa and a game with Mojtaba

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

  3. Codeforces Round #432 Div. 1 C. Arpa and a game with Mojtaba

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

  4. [CodeForces850C]Arpa and a game with Mojtaba

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

  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. 团队开发---”我爱淘“校园二手书店 NABC分析

    本项目特点之一:可预订 N:对于一些抢手的书可以提前预定,避免学生买不到书 A:网上下单,通过手机便捷购物 B:使得订书更加方便快捷 C:二手书摊.网上书店 团队成员:杨广鑫.郭健豪.李明.郑涛

  2. 2017-2018-1 1623 bug终结者 冲刺006

    bug终结者 冲刺006 by 20162328 蔡文琛 今日任务:音频素材添加 又是新的一天,小组项目有了很大的起色,已经可以在手机上试玩了. 添加背景音乐能使我们的游戏锦上添花. 音频资源需求 需 ...

  3. Twisted 安全信道

    1.安装python的SSL插件pyOpenSSL pip install pyopenssl 2.安装OpenSSL工具包 sudo apt-get install openssl sudo apt ...

  4. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  5. github提交代码到服务器的方法

    第一种情况,没有冲突:1.git add .//进入到center的项目下将本地文件打包的意思2.git pull origin dev//将服务器的代码下载到本地如果是最新的会提示Already u ...

  6. Java XML Dom解析工具

    Java XML Dom解析工具 缩进等 transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); ...

  7. Linq 生成运算符 Empty,Range,Repeat

    var c1 = Enumerable.Empty<string>();//c1.Count=0 , );//{9527,9528,9529,......9536} , );//{9527 ...

  8. python RE模块的使用

    摘要: re模块包括操作正则表达式的函数,一些工作中都需要用到,现在说明下使用方法. 使用说明: 一,re模块下的函数:            函数             描述 compile(pa ...

  9. Spring中报"Could not resolve placeholder"的解决方案

    除去properites文件路径错误.拼写错误外,出现"Could not resolve placeholder"很有可能是使用了多个PropertyPlaceholderCon ...

  10. spring-oauth-server实践:授权方式四:client_credentials 模式下access_token的产生

    授权结果 获取access_token成功, 访问资源服务器API http://localhost:9000/api-gateway-engine/unity/user_info?access_to ...