📅  最后修改于: 2020-10-30 01:10:02             🧑  作者: Mango
LCM:最小公倍数/最小公倍数
LCM代表最小公倍数。它是算术和数字系统的概念。两个整数a和b的LCM用LCM(a,b)表示。它是可被“ a”和“ b”整除的最小正整数。
例如:我们有两个整数4和6。让我们找到LCM
4的倍数是:
4, 8, 12, 16, 20, 24, 28, 32, 36,... and so on...
6的倍数是:
6, 12, 18, 24, 30, 36, 42,... and so on....
4和6的公倍数只是两个列表中的数字:
12, 24, 36, 48, 60, 72,.... and so on....
LCM是最低的公倍数,因此为12。
请参阅以下示例:
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
break
greater += 1
return lcm
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))
以下示例将显示LCM为12和20(根据用户输入)
输出: