Skip to content

Instantly share code, notes, and snippets.

@lhsfcboy
Last active June 26, 2017 01:54
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 lhsfcboy/eabf86a71690f13ac082126d6aa5fc21 to your computer and use it in GitHub Desktop.
Save lhsfcboy/eabf86a71690f13ac082126d6aa5fc21 to your computer and use it in GitHub Desktop.
GCD and LCM functions in Python
"""最小公倍数与最大公约数"""
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