24 lines
470 B
Python

def solution(x, y):
return gcd(int(x), int(y))
def gcd(x, y):
count = 0
while y != 0:
t = x % y
count += x//y
x, y = y, t
if x != 1:
return 'impossible'
return str(count-1)
tests=[
[['4', '7'], '4'],
[['2', '1'], '1'],
[['2', '4'], 'impossible'],
]
for test in tests:
result = solution(*test[0])
print(test[0][0], test[0][1], result == test[1], result, test[1])
print ''