My python 2.7 code which has been coded based on Eratosthenes prime sieve, to find all the primes under a certain limit, gives a memory error when finding primes over billion. In my code, I simply used a list to store true/false values corresponding to each number(true when it is a prime, false otherwise). Below is my code,`
def primeSieve(limit):
sieve = [True] * ((limit+1)/2)
for i in range(3, int(limit**0.5)+1, 2):
if sieve[i/2]:
sieve[(i*i)/2::i] = [False] * ((limit-i*i-1)/(2*i)+1)
return [2] + [2*i+1 for i in range(1, (limit+1)/2) if sieve[i]]
print primeSieve(100000000)
How can I modify my code to find primes over billion ? Thank you.