How to find the smallest number that is evenly divisible by all of the numbers from 1 to 20 in Python

1 Answer

0 votes
def lcm(a: int, b: int) -> int:
    # Return the Least Common Multiple of a and b.
    from math import gcd
    return abs(a * b) // gcd(a, b)


from functools import reduce

result = reduce(lcm, range(1, 21))
print(f"LCM of numbers from 1 to 20 is: {result}")



'''
run:

LCM of numbers from 1 to 20 is: 232792560

'''

 



answered Oct 10 by avibootz
...