From 7df59c9bcf31eac43c71794365e53de4e9a5610b Mon Sep 17 00:00:00 2001 From: Sidney Zhang Date: Mon, 15 Dec 2025 15:19:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(eular=5F5.py)=EF=BC=9A?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=A1=E6=97=B6=E8=A3=85=E9=A5=B0=E5=99=A8?= =?UTF-8?q?=E5=92=8CPython=E5=86=85=E7=BD=AElcm=E8=A7=A3=E5=86=B3=E6=96=B9?= =?UTF-8?q?=E6=A1=88=20=F0=9F=93=9D=20docs(eular=5F5.py)=EF=BC=9A=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=8C=E6=AF=94=E8=BE=83=E4=B8=A4=E7=A7=8D=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E7=9A=84=E6=89=A7=E8=A1=8C=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/0005.smallestMultiple/eular_5.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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))