欧几里得方法计算最大公约数Python版本
def biggest_divisor(a, b): """ 欧几里得法获得最大公约数,递归要有停止条件""" if b == 0: return a else: return biggest_divisor(b, a % b) def biggest_divisor_v2(a, b): while b>0: res = a % b a = b b = res return a if __name__ == '__main__': print(biggest_divisor(14, 16)) print(biggest_divisor_v2(14, 16))
时刻记着自己要成为什么样的人!