Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created July 5, 2011 11:20
Show Gist options
  • Select an option

  • Save Zolomon/1064668 to your computer and use it in GitHub Desktop.

Select an option

Save Zolomon/1064668 to your computer and use it in GitHub Desktop.
Least Common Multiple
#!/usr/local/bin/python3.2
def gcd(a, b):
if a == 0:
return b
while b != 0:
if a > b:
a = a - b
else:
b = b - a
return a
def lcm(a, b):
if a == 0:
return 0
return a * b / gcd(a, b)
a = float(input("a: "))
b = float(input("b: "))
print("LCM({0}, {1}) = {2}".format(a, b, lcm(a,b)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment