43 lines
939 B
Python

#!/usr/bin/env python
"""
Created on 23 Apr 2017
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 005 of Project Euler
https://projecteuler.net/problem=5
"""
from math import gcd
from utils import timeit
# The LCM of two natural numbers x and y is given by:
# def lcm(x, y):
# return x * y // math.gcd(x, y)
# It is possible to compute the LCM of more than two numbers by iteratively
# computing the LCM of two numbers, i.e. LCM(a, b, c) = LCM(a, LCM(b, c))
@timeit("Problem 005")
def compute():
"""
2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of
the numbers from 1 to 20?
"""
ans = 1
for i in range(1, 21):
ans *= i // gcd(i, ans)
return ans
if __name__ == "__main__":
print(f"Result for problem 005: {compute()}")