Skip to content

Instantly share code, notes, and snippets.

@randomdude999
randomdude999 / gcd_and_lcm.py
Last active November 4, 2017 12:52 — forked from endolith/gcd_and_lcm.py
GCD and LCM functions in Python
import math
import functools
# Greatest common divisor of more than 2 numbers. Am I terrible for doing it this way?
def gcd(*numbers):
"""Return the greatest common divisor of the given integers"""
return functools.reduce(math.gcd, numbers)
# Least common multiple is not in standard libraries? It's in gmpy, but this is simple enough: