24 lines
382 B
Python
24 lines
382 B
Python
def gcd(a, b):
|
|
while b > 0:
|
|
a, b = b, a % b
|
|
return a
|
|
|
|
def solution(x, y):
|
|
x, y = int(x), int(y)
|
|
if y < x: x, y = y, x # Reorder
|
|
|
|
count = 0
|
|
while True:
|
|
div = y/x
|
|
print(x,y)
|
|
if x == 1:
|
|
count += y-1
|
|
break
|
|
y -= x*div
|
|
count += div
|
|
if y < x: x, y = y, x
|
|
if x == y or x < 1: return "impossible"
|
|
|
|
return str(count)
|
|
|
|
print(solution(4, 7)) |