将整个游戏可以划分成若干个互不相交的子游戏。

每个子游戏的sg值只与其中的数的个数有关。而这个数不会超过30。

于是可以预处理出这个sg值表。

然后从1到n枚举,对<=sqrt(n)的部分,用个set判重。

对于大于sqrt(n)的部分,统计其中不包含在之前已经划分出来的子游戏内的数的个数,如果是奇数,就再异或上1。

/*
#include<cstdio>
#include<cstring>
#include<set>
#include<map>
using namespace std;
map<int,int>SG;
int N,n;
int sg(int x)
{
if(SG.find(x)!=SG.end())
return SG[x];
set<int>S;
for(int i=1;i<=N;++i)
if((x>>(i-1))&1)
{
int t=x;
for(int j=i;j<=N;j+=i)
if((x>>(j-1))&1)
t^=(1<<(j-1));
S.insert(sg(t));
}
for(int i=0;;++i)
if(S.find(i)==S.end())
return SG[x]=i;
}
int main()
{
freopen("test.txt","w",stdout);
scanf("%d",&n);
for(N=1;N<=n;++N)
{
SG.clear();
printf("SG[%d]=%d\n",N,sg((1<<N)-1));
}
return 0;
}
*/
#include<cstdio>
using namespace std;
typedef long long ll;
bool vis[1000001];
int SG[111],n,ans;
int main()
{
SG[1]=1;
SG[2]=2;
SG[3]=1;
SG[4]=4;
SG[5]=3;
SG[6]=2;
SG[7]=1;
SG[8]=5;
SG[9]=6;
SG[10]=2;
SG[11]=1;
SG[12]=8;
SG[13]=7;
SG[14]=5;
SG[15]=9;
SG[16]=8;
SG[17]=7;
SG[18]=3;
SG[19]=4;
SG[20]=7;
SG[21]=4;
SG[22]=2;
SG[23]=1;
SG[24]=10;
SG[25]=9;
SG[26]=3;
SG[27]=6;
SG[28]=11;
SG[29]=12;
SG[30]=14;
scanf("%d",&n);
ans^=1;
int all=0;
for(ll i=2ll;i*i<=(ll)n;++i)
{
if(!vis[i])
{
int cnt=0;
for(ll j=(ll)i;j<=(ll)n;j*=(ll)i)
{
if(j*j<=(ll)n)
vis[j]=1;
++cnt;
++all;
}
ans^=SG[cnt];
}
}
ans^=((n-all-1)&1);
puts(ans ? "Vasya" : "Petya");
return 0;
}

【博弈论】【SG函数】Codeforces Round #188 (Div. 1) D. Game with Powers的更多相关文章

  1. Codeforces Round #486 (Div. 3) D. Points and Powers of Two

    Codeforces Round #486 (Div. 3) D. Points and Powers of Two 题目连接: http://codeforces.com/group/T0ITBvo ...

  2. Codeforces Round #188 (Div. 1) B. Ants 暴力

    B. Ants Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/317/problem/B Des ...

  3. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  4. Codeforces Round #188 (Div. 2) B. Strings of Power 水题

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  5. Codeforces Round #188 (Div. 2) A. Even Odds 水题

    A. Even Odds Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/problem/ ...

  6. Codeforces Round #188 (Div. 1 + Div. 2)

    A. Even Odds 奇数个数\(\lfloor \frac{n+1}{2}\rfloor\) B. Strings of Power 从位置0开始,统计heavy个数,若当前为metal,则可以 ...

  7. Codeforces Round #486 (Div. 3)988D. Points and Powers of Two

    传送门:http://codeforces.com/contest/988/problem/D 题意: 在一堆数字中,找出尽量多的数字,使得这些数字的差都是2的指数次. 思路: 可以知道最多有三个,差 ...

  8. Codeforces Round #721 (Div. 2)A. And Then There Were K(位运算,二进制) B1. Palindrome Game (easy version)(博弈论)

    半个月没看cf 手生了很多(手动大哭) Problem - A - Codeforces 题意 给定数字n, 求出最大数字k, 使得  n & (n−1) & (n−2) & ...

  9. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

随机推荐

  1. NodeJS + PhantomJS 前端自动化资源监控

    前言:最近做前端资源监控,看了很多例子,没有达到想要的效果.首先的槽点是PhantomJS的官方文档,真鸡肋,其次是网上的例子,多数是介绍PhantomJS的用法,而并没有介绍怎么完整的去实现,跟官方 ...

  2. [USACO08DEC] 秘密消息Secret Message

    题目描述 Bessie is leading the cows in an attempt to escape! To do this, the cows are sending secret bin ...

  3. windows10-seaslog安装笔记

    1.seasLog在windows下的安装 首先,要下载seasLog的dll文件,下载地址:http://pecl.php.net/package/SeasLog  选择对应你的系统和php版本的d ...

  4. Spring学习--集合属性

    Spring 中可以通过一组内置的 xml 标签(例如: <list> , <set> 或 <map>) 来配置集合属性. 配置java.util.Set 需要使用 ...

  5. 数学:Lucas定理

    利用Lucas定理解决大组合数取模 Lucas定理是用来求 C(n,m) mod p,p为素数的值.(注意:p一定是素数) Lucas定理用来解决大组合数求模是很有用的 Lucas定理最大的数据处理能 ...

  6. 【CF1027F】Session in BSU(dsu,基环树)

    题意:给出n场考试,每场考试有2天可以通过(第ai与bi天).每天最多参加一场考试,现在要求所有考试全部通过的最小天数 n<=1e6,1<=a[i]<b[i]<1e9 思路:F ...

  7. 【洛谷 UVA11417】 GCD(欧拉函数)

    我们枚举所有gcd \(k\),求所有\(gcd=k\)的数对,记作\(f(k)\),那么\(ans=\sum_{i=1}^{n}(f(i)-1)*i\).为什么减1呢,观察题目,发现\(j=i+1\ ...

  8. BZOJ1037 DP

    2013-11-15 21:51 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1037 拿到这道题想到了DP,后来发现三维无法确定的表示状 ...

  9. sphinx 分词搭建手册

    步奏1. yum install make gcc g++ gcc-c++ libtool autoconf automake imake mysql-devel libxml2-devel expa ...

  10. 【Android开发日记】之入门篇(十四)——Button控件+自定义Button控件

        好久不见,又是一个新的学期开始了,为什么我感觉好惆怅啊!这一周也发生了不少事情,节假日放了三天的假(好久没有这么悠闲过了),实习公司那边被组长半强制性的要求去解决一个后台登陆的问题,结果就是把 ...