# 最大公约数,最小公倍数 def yueshu(num, alist=None):
""" 这个方法是核心 :param num: int :param alist: None :return: alist """ if alist == None:
alist = []
for i in range(2, num // 2 + 1):
if not num % i: # 整除 alist.append(i)
return yueshu(num // i, alist)
else:
alist.append(num)
return alist
def big_small(num1, num2):
list1 = yueshu(num1)
list2 = yueshu(num2)
alist = []
for i in list1:
if i in list2:
alist.append(i)
list2.remove(i)
pub = 1
for i in alist:
pub = pub * i
pub2 = num1 * num2 / pub
return pub, pub2
if __name__ == '__main__':
big, small = big_small(15, 18)
print big, small
自己写的,不一定对,哈哈哈哈