Created
March 16, 2017 05:10
-
-
Save ramachandrajr/5b84d75063932448592be9c319df43f8 to your computer and use it in GitHub Desktop.
Python LCM Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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