code force A. Epic Game(gcd求最大公约数)

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 ab and n who wins the game.

Input

The only string contains space-separated integers ab 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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值