-
Notifications
You must be signed in to change notification settings - Fork 4
/
gcd.cpp
50 lines (41 loc) · 760 Bytes
/
gcd.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
const int N = 2e5 + 11;
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
void solve() {
int a,b,n;
cin>>a>>b>>n;
int take = 0;
int turn = 0;
bool simonPass = 1;
while (n != 0) {
turn = (simonPass? a:b);
take = gcd(turn,n);
if( take <= n ) {
n -= take;
simonPass = 1 - simonPass;
} else {
break;
}
}
cout<<simonPass<<endl;
}
int main() {
freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int no_of_test_cases = 1;
// cin >> no_of_test_cases;
while (no_of_test_cases--)solve();
return 0;
}