Last active
June 26, 2017 01:54
-
-
Save lhsfcboy/eabf86a71690f13ac082126d6aa5fc21 to your computer and use it in GitHub Desktop.
GCD and LCM functions in Python
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(*numbers): | |
"""Return the greatest common divisor of the given integers""" | |
from fractions import gcd | |
return reduce(gcd, numbers) | |
def lcm(*numbers): | |
"""Return lowest common multiple.""" | |
def lcm(a, b): | |
return (a * b) // gcd(a, b) | |
return reduce(lcm, numbers, 1) | |
# Numbers are positive integers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment