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, ...
随机推荐
- Problem V
Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th ...
- poj 3340 Barbara Bennett's Wild Numbers(数位DP)
Barbara Bennett's Wild Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3153 A ...
- 解决打开MATLAB时出现“Waring:could not read file classpath.txt”,等问题
估计刚安装好的matlab是不会出现这个问题的,出现问题肯定是在某一次用360或者电脑管家清理垃圾之后才会出现这个问题. 首先声明我的matlab版本是matlab R2014a,下载链接:(额,网盘 ...
- 第一数学归纳法 vs 第二数学归纳法 vs 良序定理
相关: 第一数学归纳法 vs 第二数学归纳法 vs 良序定 第二数学归纳法:硬币问题和堆垛游戏 第一数学归纳法:施塔特中心的地板砖 良序原理:算术基本定理的证明 From : Mathematics ...
- Python解决 从1到n整数中1出现的次数
最近在看<剑指Offer>,面试题32的题目:输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数.例如输入12,从1到12这些整数中包含1的数字有1.10.11和12,1一共出 ...
- angualr4 路由 总结笔记
使用cli命令创建根路由模块 ng g cl app.router 或自己建一个路由配置文件 如:app/app.router.ts // app/app.router.ts // 将文件修改为 im ...
- vue 2 仿IOS 滚轮选择器 从入门到精通 (一)
大家好,由于最近从事的是微信公众号和APP内嵌 H5开发,避免不了开发一些和native相同的操作功能,就如接下来说的 仿IOS滚轮选择器. 先来个截图: 接下来具体介绍如何实现的.能力有限避免不了错 ...
- [转载] Storm:最火的流式处理框架
转载自http://www.cnblogs.com/langtianya/p/5199529.html 伴随着信息科技日新月异的发展,信息呈现出爆发式的膨胀,人们获取信息的途径也更加多样.更加便捷,同 ...
- [转载] Netty源码分析
转载自http://blog.csdn.net/kobejayandy/article/details/11836813 Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开发高性能.高 ...
- cgg之字面值
字面值时源代码中用来描述固定值的记号,可能是整数.浮点数.字符或者字符串 2.1 整数常量 除了常见的十进制数外,还有八进制(以数字0开头)或者十六进制(0x/0X)表示法. #include < ...