GCD and LCM using Euclid algo
#product of two number = lcm * gcd
def gcd(a,b):
if a==0:
return b
return gcd(b%a,a)
def lcm(a,b):
prod=a*b
hcf=gcd(a,b)
return prod//hcf
a,b=map(int,input().split())
print("lcm: ",lcm(a,b)," ","gcd: ",gcd(a,b))
#product of two number = lcm * gcd
def gcd(a,b):
if a==0:
return b
return gcd(b%a,a)
def lcm(a,b):
prod=a*b
hcf=gcd(a,b)
return prod//hcf
a,b=map(int,input().split())
print("lcm: ",lcm(a,b)," ","gcd: ",gcd(a,b))
Comments
Post a Comment