CF119A.Epic Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number aa and Antisimon receives number bb . They also have a heap of nn 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 aa , bb and nn who wins the game.

输入格式

The only string contains space-separated integers aa , bb and nn ( 1<=a,b,n<=1001<=a,b,n<=100 ) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.

输出格式

If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).

输入输出样例

  • 输入#1

    3 5 9
    

    输出#1

    0
  • 输入#2

    1 1 100
    

    输出#2

    1

说明/提示

The greatest common divisor of two non-negative integers aa and bb is such maximum positive integer kk , that aa is divisible by kk without remainder and similarly, bb is divisible by kk without remainder. Let gcd(a,b)gcd(a,b) represent the operation of calculating the greatest common divisor of numbers aa and bb . Specifically, gcd(x,0)=gcd(0,x)=xgcd(x,0)=gcd(0,x)=x .

In the first sample the game will go like that:

  • Simon should take gcd(3,9)=3gcd(3,9)=3 stones from the heap. After his move the heap has 66 stones left.
  • Antisimon should take gcd(5,6)=1gcd(5,6)=1 stone from the heap. After his move the heap has 55 stones left.
  • Simon should take gcd(3,5)=1gcd(3,5)=1 stone from the heap. After his move the heap has 44 stones left.
  • Antisimon should take gcd(5,4)=1gcd(5,4)=1 stone from the heap. After his move the heap has 33 stones left.
  • Simon should take gcd(3,3)=3gcd(3,3)=3 stones from the heap. After his move the heap has 00 stones left.
  • Antisimon should take gcd(5,0)=5gcd(5,0)=5 stones from the heap. As 0<5 , it is impossible and Antisimon loses.

In the second sample each player during each move takes one stone from the heap. As nn is even, Antisimon takes the last stone and Simon can't make a move after that.

首页