How to calculate LCM using Python
But, First we need to know that --
What is a LCM?
LCM (Lowest Common Multiple) is the lowest multiple that is common in 2 or more numbers. But what is a Multiple.
What is a Multiple?
A Multiple is the product of a number and other number whose range is starting from 2.
Algorithm behind finding the LCM -
- Get two numbers from the user to calculate the LCM.
- Calculate the multiples of the two numbers.
- Now, compare the multiples for common ones and write down the smallest one.
n1 = int(input())
n2 = int(input())
q,r,s = [],[],[]
for i in range (1,10):
q.append(n1*i)
r.append(n2*i)
for a in q:
for b in r:
if a == b:
s.append(a)
print (min(s))
0 Comments