[博弈论] cf317 D Game with Powers
@(ACM题目)[博弈论]
#include<iostream>
#include<cstdio>
#include <cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<stack>
using namespace std;
typedef long long LL;
/*
const int maxn = 1e9+1e8;
char sg[maxn];
int getsg(int S)
{
if(sg[S] != -1) return sg[S];
bool vis[31] = {0};
for(int i = 1; i <= 30; i++)
if(S&(1<<(i-1)))
{
int tmp = S;
for(int j = i; j <= 30; j += i)
{
if(S&(1<<(j-1))) tmp -= 1<<(j-1);
}
vis[getsg(tmp)] = 1;
}
for(int i = 0; i <= 30; i++)
if(!vis[i]) return sg[S] = i;
}
int main()
{
memset(sg, -1, sizeof sg);
sg[0] = 0;
getsg((1<<29)-1);
for(int i = 0; i < 30; i++) cout<<(int)sg[(1<<i)-1]<<",";
return 0;
}
*/
const int maxn = 1e5;
int sg[] = {0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12};
bool vis[maxn] = {0};
int main()
{
int n, m; cin>>n;
if(n==1) return puts("Vasya"), 0;
m = sqrt(n+0.5);
int res = sg[1];
int dif = 0;
for(int i = 2; i <= m; i++)
if(!vis[i])
{
int k = 0;
for(LL j = i; j <= n; j *= i)
{
if(j <= m) vis[j] = true;
else dif++;
k++;
}
res ^= sg[k];
}
if((n-m-dif)&1) res ^= sg[1];
puts(res?"Vasya":"Petya");
return 0;
}