1from math import gcd
2def lcm(a,b):
3 return a*b/(gcd(a,b))
4print(lcm(12,70))
5//output: 420
1# Write a Program to Find LCM of two numbers entered by user
2
3num1 = int(input("Enter first number: "))
4num2 = int(input("Enter second number: "))
5
6if num1 > num2:
7 max_num = num1
8else:
9 max_num = num2
10
11while True :
12 if(max_num % num1 == 0 and max_num % num2 == 0):
13 print(" The LCM of ",num1," and ",num2," is ", max_num )
14 break
15 max_num = max_num+1
16
1# Python program to find the L.C.M. of two input number
2
3# This function computes GCD
4def compute_gcd(x, y):
5
6 while(y):
7 x, y = y, x % y
8 return x
9
10# This function computes LCM
11def compute_lcm(x, y):
12 lcm = (x*y)//compute_gcd(x,y)
13 return lcm
14
15num1 = 54
16num2 = 24
17
18print("The L.C.M. is", compute_lcm(num1, num2))
19
1def find_lcm(x, y):
2
3 # choose the higher number
4 if x > y:
5 greater = x
6 else:
7 greater = y
8
9 while(True):
10 if((greater % x == 0) and (greater % y == 0)):
11 lcm = greater
12 break
13 greater += 1
14
15 return lcm
16
17num1 = 22 # You can input the numbers if u want
18num2 = 56
19
20# call the function
21print("L.C.M :", find_lcm(num1, num2))
1def lcm(a, b):
2 i = 1
3 if a > b:
4 c = a
5 d = b
6 else:
7 c = b
8 d = a
9 while True:
10 if ((c * i) / d).is_integer():
11 return c * i
12 i += 1;