Thursday, March 20, 2014

Codeforces Beta Round #90, problem: (A) Epic Game solution

Codeforces Beta Round #90, problem: (A) Epic Game: http://codeforces.com/problemset/problem/119/A

Codeforces Beta Round #90, problem: (A) Epic Game solution: http://ideone.com/EpNdwC

#include <iostream>
#include <cstdio>
using namespace std;

int gcd(int u, int v) {
    if(u==v) return u;
    if(v==0) return u;
    if(u==0) return v;
    if(~u & 1) {
        if(v & 1) return gcd(u>>1, v);
        else return gcd(u>>1, v>>1)<<1;
    }
    if(u>v) return gcd(u-v, v);
    return gcd(v-u, u);
}

int main() {
    int a, b, n;
    scanf("%d%d%d", &a, &b, &n);
    while(n>=0) {
        if(n==0) {
            printf("1");
            break;
        }
        n-=gcd(a, n);
        if(n==0) {
            printf("0");
            break;
        }
        n-=gcd(b, n);
    }
    return 0;
}

No comments:

Post a Comment