Codeforces 850C Arpa and a game with Mojtaba
题意:给定一个正整数序列,两人轮流对这个数列进行如下修改:选取一个素数p和一个整数k将序列中能整除p^k的数除以p^k,问谁有必胜策略。
借此复习一下sg函数吧,sg(x) = mex ( sg(y) |y是x的后继结点 )。我们不难发现不同的质因子是互不影响的,因此我们可以把不同的质因子归为不同的game。因为每次操作对整个序列有效,所以序列中p^k的个数也是不影响答案的。因此我们可以用一个二进制位表示当前序列是否存在p^k,如果存在,则其第(k-1)位为1。由是把所有game的sg异或起来即可得到答案。
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000000+10
int n,tot=,flag=,prime[MAXN];
bool is[MAXN];
map<int,int>sg,st;
int getsg(int x){
if(x==)return ;
if(sg.count(x))return sg[x];
map<int,int>vis;
int p=x,t=;
while(p)p>>=,t++;
for(int i=;i<=t;i++)
vis[getsg((x>>i)|(x&((<<i-)-)))]=;
for(int i=;;i++)
if(!vis[i])return sg[x]=i;
}
void form(){
memset(is,true,sizeof(is));
is[]=false;
for(int i=;i<=MAXN-;i++){
if(is[i])prime[++tot]=i;
for(int j=;j<=tot&&i*prime[j]<=MAXN-;j++){
is[i*prime[j]]=false;
if(i%prime[j]==)break;
}
}
}
void deal(int x){
for(int i=;prime[i]*prime[i]<=x;i++){
int t=;
while(x%prime[i]==){
x/=prime[i];
t++;
}
if(t)st[prime[i]]|=<<(t-);
}
if(x!=)st[x]|=;
}
int main(){
form();
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;
scanf("%d",&x);
deal(x);
}
map<int,int>::iterator it;
for(it=st.begin();it!=st.end();it++)flag^=getsg(it->second);
if(flag)printf("Mojtaba\n");
else printf("Arpa\n");
return ;
}
Codeforces 850C Arpa and a game with Mojtaba的更多相关文章
- Codefroces 850C Arpa and a game with Mojtaba
Description两个人Van♂游戏.给出$n$个正整数$ai$两人轮流操作,每次选出一个素数$p$和一个幂数$k$,选择的前提为该$n$个数中有$p^{k}$的倍数.接着将所有的$p^{k}$的 ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(启发式合并)
codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...
- 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. 最后不能操作者负. 问先手是否有必胜策略. 思路: 显然 ...
- 【Codeforces 851D Arpa and a list of numbers】
Arpa的数列要根据GCD变成好数列. ·英文题,述大意: 给出一个长度为n(n<=5000000)的序列,其中的元素a[i]<=106,然后输入两个数x,y(x,y<=1 ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ o ...
- Codeforces 741B Arpa's weak amphitheater and Mehrdad's valuable Hoses
[题目链接] http://codeforces.com/problemset/problem/741/B [题目大意] 给出一张图,所有连通块构成分组,每个点有价值和代价, 要么选择整个连通块,要么 ...
- CodeForces - 851B -Arpa and an exam about geometry(计算几何)
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a, ...
随机推荐
- ubuntu-17.10 安装 FANN
因为想用C语言写神经网络,不用已有的库的话,又太难了,所以准备安装一个夸平台的FANN库, 源文件下载地址http://leenissen.dk/fann/wp/download/,我下载的是最新 ...
- dp百题大过关(第一场)
好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem 这 ...
- J - Scarily interesting! URAL - 2021
This year at Monsters University it is decided to arrange Scare Games. At the Games all campus gathe ...
- 关于php加密库加密数据上传数据库或解密出错的问题
php加密拓展库随着php版本的更新,函数的使用方法有所改变,所以加密模式推荐使用ecb,其中加密算法19种,加密模式8种,通过这种方式加密后的数据上传数据库后提取出来进行解密会发现结果是乱码,我认为 ...
- python的学习之路day1
软件:python3.pycharm开发工具 python的开始:print("hello world") 注意:python3需要加上() 1.变量是什么:在程序运行过程中它的值 ...
- 一:Spring Boot、Spring Cloud
上次写了一篇文章叫Spring Cloud在国内中小型公司能用起来吗?介绍了Spring Cloud是否能在中小公司使用起来,这篇文章是它的姊妹篇.其实我们在这条路上已经走了一年多,从16年初到现在. ...
- 高效sql2005分页存储过程
高效分页存储过程 --分页存储过程示例 Alter PROCEDURE [dbo].[JH_PageDemo] @pageSize int = 9000000000, @pageIndex int = ...
- JDBC数据源 使用JNDI连接池实现数据库的连接
0.引言 许多Web应用程序需要通过JDBC驱动程序访问数据库,以支持该应用程序所需的功能.Java EE平台规范要求Java EE应用程序服务器为此目的提供一个DataSource实现(即,用于JD ...
- Redis全面介绍
最近重新认识了一下Redis,借着这个机会,也整理一篇算是比较详尽和全面的文章吧. 缓存 缓存就是数据交换的缓冲区(称作Cache)——摘自百度百科.无论是在计算机硬件体系结构还是软件体系结构中, ...
- [转载] Jupiter代码审查工具使用参考
转载自http://blog.csdn.net/jemlee2002/article/details/5715355 一. Jupiter 是什么? 这里的 Jupiter 是一个开源的代 ...