求最大公约数python代码
以下是求最大公约数的Python代码:
def gcd(a, b):
"""
计算a和b的最大公约数
"""
if b == 0:
return a
else:
return gcd(b, a % b)
使用示例:
print(gcd(24, 36)) # 输出12
print(gcd(13, 17)) # 输出1
原文地址: https://www.cveoy.top/t/topic/fFeS 著作权归作者所有。请勿转载和采集!