QP – LCM

Find the least common multiple of an array of numbers

#!/usr/bin/python3
import sys
from math import gcd

def lcm_list(nums):
    from functools import reduce
    def lcm(a, b):
        return a * b // gcd(a, b)
    return reduce(lcm, nums)

nums = list(map(int, sys.argv[1:]))
print(lcm_list(nums))

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment