forked from anubhab91/CodeForces-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEpicGame.py
More file actions
41 lines (36 loc) · 1023 Bytes
/
EpicGame.py
File metadata and controls
41 lines (36 loc) · 1023 Bytes
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
__author__ = 'Devesh'
'''
http://codeforces.com/problemset/problem/119/A
Solution: Implement turns for each player using a turn variable and checking its value to be
odd or even. GCD is implemented using recursive euclid algorithm. Rest all is pretty straight-
forward.
'''
#GCD using euclid algorithm
def gcd(a,b):
if(b == 0):
return a
return gcd(b, a%b)
def solve(a,b,n):
turn = 0
while(True):
if(turn%2==0):
#print "Simon turn"
toPick = gcd(a,n)
if(n>=toPick):
n-=toPick
else:
return 1 #consider win for Antisimon
else:
#print "Antisimon turn"
toPick = gcd(b,n)
if(n>=toPick):
n-=toPick
else:
return 0 #consider win for Simon
turn+=1
if __name__ == "__main__":
inputs = raw_input()
a = int(inputs.split(" ")[0])
b = int(inputs.split(" ")[1])
n = int(inputs.split(" ")[2])
print solve(a,b,n)