def greatest_common_denominator(a, b):
a, b = b, a % b
def least_common_multiple(a, b):
return (a * b) / greatest_common_denominator(a, b)
if len(li) == 2:
return least_common_multiple(li, li)
check = li.pop()
return least_common_multiple(check, least_common_multiple_range(li))
print least_common_multiple_range(range(1, 21))
The most significant part here is that you can compute the least common multiple by computing the greatest common denominator and using it to divide the product of the two numbers.
(Yes, the language itself isn't important for me. Just the mathematical challenge.)
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.