Codeforce 119A - Epic Game (模拟)

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
3 5 9
output
0
input
1 1 100
output
1
Note

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

In the first sample the game will go like that:

  • Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.
  • Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.
  • Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.
  • Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.
  • Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.
  • Antisimon should take gcd(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 n is even, Antisimon takes the last stone and Simon can't make a move after that.

 题解:直接模拟就好啦

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 using namespace std;
13 #define lowbit(x) (x&(-x))
14 #define max(x,y) (x>y?x:y)
15 #define min(x,y) (x<y?x:y)
16 #define MAX 100000000000000000
17 #define MOD 1000000007
18 #define pi acos(-1.0)
19 #define ei exp(1)
20 #define PI 3.141592653589793238462
21 #define INF 0x3f3f3f3f3f
22 #define mem(a) (memset(a,0,sizeof(a)))
23 typedef long long ll;
24 const int N=105;
25 const int mod=1e9+7;
26 int a[N];
27 int gcd(int a,int b)
28 {
29     return (b>0)?gcd(b,a%b):a;
30 }
31 int main()
32 {
33     int a,b,n;
34     cin>>a>>b>>n;
35     while(1){
36         if(gcd(a,n)<=n){
37             n-=gcd(a,n);
38         }
39         else {
40             cout<<1<<endl;
41             break;
42         }
43         if(gcd(b,n)<=n){
44             n-=gcd(b,n);
45         }
46         else {
47             cout<<0<<endl;
48             break;
49         }
50     }
51     return 0;
52 }
View Code
posted @ 2017-07-30 15:56  wydxry  阅读(287)  评论(0编辑  收藏  举报
Live2D