"""The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million.""" import numpy as np def sieve(n): if n <= 1: return np.array([]) u = int( np.sqrt(n) ) plist = np.arange(1, n+1, 2, dtype=int) for k in np.arange(1, u): if plist[k]: plist[ (plist[k] * plist[k])/2 :: plist[k] ] = 0 plist[0] = 2 return plist[np.flatnonzero( plist )] print np.sum( sieve(2000000).tolist() )