Skip to content

Instantly share code, notes, and snippets.

@ramachandrajr
Created March 16, 2017 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramachandrajr/5b84d75063932448592be9c319df43f8 to your computer and use it in GitHub Desktop.
Save ramachandrajr/5b84d75063932448592be9c319df43f8 to your computer and use it in GitHub Desktop.
Python LCM Algorithm
def gcd(a, b):
"""Return greatest common divisor using euclid's Algorithm
."""
# Run while b is not equal to zero
while b:
a, b = b, a % b
print "a: %d, b: %d." % (a, b)
print "=" * 10
return a
def lcm(a, b):
"""Return the lowest common multiple."""
return a * b // gcd(a, b)
def lcmm(*args):
"""Return lcm of args."""
return reduce(lcm, args)
print lcmm(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment