Returns the sum of all the primes below n. >>> solution(1000) 76127 >>> solution(5000) 1548136 >>> solution(10000) 5736396 >>> solution(7) 10
(n: int = 2000000)
| 49 | |
| 50 | |
| 51 | def 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 | |
| 68 | if __name__ == "__main__": |