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))
1# Python Program to find the L.C.M. of two input number
2#naive method
3def compute_lcm(x, y):
4
5 # choose the greater number
6 if x > y:
7 greater = x
8 else:
9 greater = y
10
11 while(True):
12 if((greater % x == 0) and (greater % y == 0)):
13 lcm = greater
14 break
15 greater += 1
16
17 return lcm
18
19num1 = 54
20num2 = 24
21
22print("The L.C.M. is", compute_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;