MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_005/sol2.py:40–56  ·  view source on GitHub ↗

Returns the smallest positive number that is evenly divisible (divisible with no remainder) by all of the numbers from 1 to n. >>> solution(10) 2520 >>> solution(15) 360360 >>> solution(22) 232792560

(n: int = 20)

Source from the content-addressed store, hash-verified

38
39
40def solution(n: int = 20) -> int:
41 """
42 Returns the smallest positive number that is evenly divisible (divisible
43 with no remainder) by all of the numbers from 1 to n.
44
45 >>> solution(10)
46 2520
47 >>> solution(15)
48 360360
49 >>> solution(22)
50 232792560
51 """
52
53 g = 1
54 for i in range(1, n + 1):
55 g = lcm(g, i)
56 return g
57
58
59if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls 1

lcmFunction · 0.85

Tested by

no test coverage detected