problem010.py (681B)
1 # problemName = "Summation of primes" 2 # problemNum = 10 3 # solutionBy = "FIGBERT" 4 # language = "Python" 5 # dateCompleted = "28/01/2020" 6 7 def sieve_of_eratosthenes(limit): 8 prime = [True for _ in range(limit+1)] 9 prime_pos = 2 10 while (prime_pos**2 <= limit): 11 if (prime[prime_pos] == True): 12 for i in range(prime_pos * 2, limit + 1, prime_pos): 13 prime[i] = False 14 prime_pos += 1 15 prime[0:2] = [False, False] 16 return [prime_pos for prime_pos in range(limit + 1) if prime[prime_pos]] 17 18 if __name__ == "__main__": 19 primes = sieve_of_eratosthenes(2000000) 20 print(f"The sum of all the primes below two million is {sum(primes)}")