Menu

gitpiper

lcm python Code Snippet in 2024

mathlistintermediate

Last Updated: 13 May 2024

Returns the least common multiple of a list of numbers.

  • Use functools.reduce(), math.gcd() and lcm(x,y) = x * y / gcd(x,y) over the given list.
from functools import reduce from math import gcd def lcm(numbers): return reduce((lambda x, y: int(x * y / gcd(x, y))), numbers)
lcm([12, 7]) # 84 lcm([1, 3, 4, 5]) # 60

python snippet similar to lcm For You in May 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️