The problem is to find LCM of two numbers. I have tried to solve the problem in two ways. First by using the LCM formula :LCM (a,b)= a*b/gcd(a,b).Second by finding out the multiples of each number and then finding the first common multiple. Below are the codes that I have written:
#Using the LCM formula LCM = a*b / gcd(a,b) def LCM(x , y): """ define a function LCM which takes two integer inputs and return their LCM using the formula LCM(a,b) = a*b / gcd(a,b) """ if x==0 or y == 0: return "0" return (x * y)/GCD(x,y) def GCD(a , b): """ define a function GCD which takes two integer inputs and return their common divisor""" com_div = i =2 while i<= min(a,b): if a % i == 0 and b % i ==0: com_div.append(i) i = i+1 return com_div[-1] print LCM(350,1) print LCM(920,350)
#Finding the multiples of each number and then finding out the least common multiple def LCM(x , y): """ define a function LCM which take two integerinputs and return their LCM""" if x==0 or y == 0: return "0" multiple_set_1 =  multiple_set_2 =  for i in range(1,y+1): multiple_set_1.append(x*i) for j in range(1,x+1): multiple_set_2.append(y*j) for z in range (1,x*y+1): if z in multiple_set_1: if z in multiple_set_2: return z break print LCM(350,450)
I want to know which one of them is a better way of solving the problem and why . Also suggest what other border cases should be covered.
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!