最小公倍数 求解两个整数(不能是负数)的最小公倍数 方法一:穷举法 def LCM(m, n): if m*n == 0: return 0 if m > n: lcm = m else: lcm = n while lcm%m or lcm%n: lcm += 1 return lcm 方式二:公式lcm = a*b/gcd(a, b) def gcd(m,n): if not n: return m else: return gcd(n, m%n) def LCM(m, n): if m*n…
本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multiple # 2520 is the smallest number that can be divided by # each of the numbers from 1 to 10 without any remainder. # What is the smallest positive num…
def gongyueshu(m,n): if m<n: m,n=n,m elif m==n: return m if m/n==int(m/n): return n else: for i in range(n,0,-1): if m/i==int(m/i) and n/i==int(n/i): return i def gongbeishu(m,n): aa=[] if m<n: m,n=n,m elif m==n: return m while gongyueshu(m,n)!=1: f…
def demo(m, n): if m > n: m, n = n, m p = m * n while m != 0: r = n % m n = m m = r return (int(p / n), n) val = demo(20, 30) print('最小公倍数为:', val[0]) print('最大公因数为:', val[1]) #输出结果 #最小公倍数为: 60 #最大公因数为: 10…