MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_010/sol1.py:51–65  ·  view source on GitHub ↗

Returns the sum of all the primes below n. >>> solution(1000) 76127 >>> solution(5000) 1548136 >>> solution(10000) 5736396 >>> solution(7) 10

(n: int = 2000000)

Source from the content-addressed store, hash-verified

49
50
51def solution(n: int = 2000000) -> int:
52 """
53 Returns the sum of all the primes below n.
54
55 >>> solution(1000)
56 76127
57 >>> solution(5000)
58 1548136
59 >>> solution(10000)
60 5736396
61 >>> solution(7)
62 10
63 """
64
65 return sum(num for num in range(3, n, 2) if is_prime(num)) + 2 if n > 2 else 0
66
67
68if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

is_primeFunction · 0.70

Tested by

no test coverage detected