Python求任意多个数的最小公倍数和最大公因数

 

def Common_multiple(number1, number2):  # 求两个数的最大公因数
   while number1 % number2 != 0:
       number1, number2 = number2, (number1 % number2)
   return number2


def Maximum_common_divisor(*number):  # 求任意多个数的最大公因数
   while len(number) > 1:
       number = [Common_multiple(number[i], number[i+1]) for i in range(0, len(number)-1)]
   return number[0]


def Minimum_common_multiple(*number):  # 求任意多个数的最小公倍数
   while len(number) > 1:
       number = [number[i]*number[i+1]/Common_multiple(number[i], number[i+1]) for i in range(0, len(number)-1)]
   return int(number[0])

 

你可能感兴趣的:(Python,[编程日常]Python)