A. Epic Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take).
Your task is to determine by the given a, b and n who wins the game.
Input
The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
Output
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
Examples
input
Copy
3 5 9
output
Copy
0
input
1 1 100
output
1
题意:每回合取走石子数和初始数的最大公约数,无法取时即失败
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
const int MAXN = 2e6+5;
ll n,m,flag,flag1,ma,mi,ans,sum,T,k,x,y;
int a[MAXN],b[MAXN],dp[MAXN];
char c[MAXN];
int mapp[5001][5001];
string str,str1,str2;
set<char> ss;
vector<char> v;
map<string,int> M;
bool judge(int x){if(x==2||x==3)return false;for(int i=2;i<=sqrt(x);i++){if(x%i==0)return true;}return false;}
int gcd(int a,int b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
int main()
{
cin>>x>>y>>n;
flag=0;
while(n)
{
if(flag==0)
{
if(gcd(x,n)>n)
{
break;
}
n-=gcd(x,n);
flag=1;
}
else
{
if(gcd(y,n)>n)
{
break;
}
n-=gcd(y,n);
flag=0;
}
}
if(flag)
cout<<0<<endl;
else
cout<<1<<endl;
return 0;
}