diff --git a/solutions/0005.smallestMultiple/eular_5.py b/solutions/0005.smallestMultiple/eular_5.py index a72f9f6..82a4685 100644 --- a/solutions/0005.smallestMultiple/eular_5.py +++ b/solutions/0005.smallestMultiple/eular_5.py @@ -5,6 +5,18 @@ What is the smallest positive number that is evenly divisible by all of the numb import math import random +import time + + +def timer(func): + def wrapper(*args, **kwargs): + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + print(f"{func.__name__} took {end_time - start_time:.6f} seconds") + return result + + return wrapper def is_probable_prime(n: int, trials: int = 10) -> bool: @@ -54,6 +66,7 @@ def primes_up_to(n: int) -> list[int]: return primes +@timer def smallest_multiple(n: int) -> int: result = 1 for p in primes_up_to(n): @@ -63,5 +76,12 @@ def smallest_multiple(n: int) -> int: return result +@timer +def python_solution(n: int) -> int: + ls = list(range(1, n + 1)) + return math.lcm(*ls) + + if __name__ == "__main__": print(smallest_multiple(20)) + print(python_solution(20))