How should I store a value in list_=[ ]
while calculating the LCM between two numbers? I need to store every factor for both the numbers.
My code is:
def lcm(x, y):
if x > y:
greater = x
else:
greater = y
lcms =[]
while(True):
if((greater % x == 0) and (greater % y == 0)):
lcm = greater
lcms.append(lcm)
break
greater += 1
print(lcms)
return lcm
t= int(input())
for T in range(1, t+1):
l= list(map(int, input().split()))
print (lcm(x=l[0],y=l[1]))
Suppose Test case inputs are t=1
and l = [9, 20]
, where the output is 180
.
So, I need to print a list where it contains every LCM integer form
both the inputs and then I need to print the LCM between them.
I get the LCM value but don't able to print list = [ ]
that contains LCM like this [2,3,5]
instead of [2,2,3,3,5]
(Reason: I also need to remove the repeating integer values from the list.)