A. epic game

Source: Internet
Author: User
Tags greatest common divisor
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 has es one fixed positive integer that doesn't change throughout the game. Simon has es numberAAnd
Antisimon distinct es numberB. They also have a heapNStones.
The players take turns to make a move and Simon starts. during a move a player shoshould take from the heap the number of stones equal to the greatest common divisor of the fixed number he has stored Ed 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 givenA,BAndNWho
Wins the game.

Input

The only string contains space-separated IntegersA,BAndN(1 digit ≤ DigitA, Bytes,B, Bytes,NLimit ≤0000100)
-The fixed numbers Simon and antisimon have specified ed 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 ).

Sample test (s) Input
3 5 9
Output
0
Input
1 1 100
Output
1
Note

The greatest common divisor of two non-negative integersAAndBIs
Such maximum positive integerK, ThatAIs divisible
ByKWithout remainder and similarly,BIs divisible
ByKWithout remainder. LetGCD(A, Bytes,B) Represent
The operation of calculating the greatest common divisor of numbersAAndB.
Specifically,GCD(X, Required 0) bytes = bytesGCD(0, success,X) Bytes = bytesX.

In the first sample the game will go like that:

  • Simon shoshould takeGCD(3, 9) threads = threads 3 stones from the heap. After his move the heap has 6 stones
    Left.

  • Antisimon shocould takeGCD(5, six 6) pipeline = pipeline 1 stone from the heap. After his move the heap has 5 stones
    Left.

  • Simon shoshould takeGCD(3, Phase 5) pipeline = pipeline 1 stone from the heap. After his move the heap has 4 stones
    Left.

  • Antisimon shocould takeGCD(5, Release 4) pipeline = pipeline 1 stone from the heap. After his move the heap has 3 stones
    Left.

  • Simon shoshould takeGCD(3, numbers 3) Numbers = numbers 3 stones from the heap. After his move the heap has 0 stones
    Left.

  • Antisimon shocould takeGCD(5, interval 0) rows = minute 5 stones from the heap. As 0 rows <minute 5,
    It is impossible and antisimon loses.

    In the second sample each player during each move takes one stone from the heap.NIs even, antisimon takes the last stone and Simon can't make a move
    After that.

  • Solution Description: moving phase division, Euclidean Theorem

    #include <iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;void swap(int & a, int & b) { int c = a; a = b; b = c; } int gcd(int a,int b) { if(0 == a ) { return b; } if( 0 == b) { return a; } if(a > b) { swap(a,b); } int c; for(c = a % b ; c > 0 ; c = a % b) { a = b; b = c; } return b; }int main(){int a,b,n;int flag;scanf("%d %d %d",&a,&b,&n);while(1){n-=gcd(a,n);if(n==0){flag=1;printf("0\n");break;}n-=gcd(b,n);if(n==0){flag=2;printf("1\n");break;}}return 0;}

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.