def gcd(a, b):
print(a, b)
if min(a, b) == 1:
return 1
else:
if (min(a, b) % min(a, b) == 0) and (max(a, b) % min(a, b) == 0):
print('else: ', min(a, b))
return min(a, b)
gcd(min(a, b)-1, max(a, b))
为什么上面的代码没有为gcd(9,12)返回6?这就是我得到的:
gcd(6,12)
6 12
else: 6
Out[98]: 6
gcd(9,12)
9 12
8 12
7 12
6 12
else: 6