Just to clarify, this is not a homework problem :)
I wanted to find primes for a math application I am building & came across Sieve of Eratosthenes approach.
The fastest implementation I could come up with:
isprime = [True]*N isprime[0] = isprime[1] = False for i in range(4, N, 2): isprime[i] = False for i in range(3, N, 2): if isprime[i]: for j in range(i*i, N, 2*i): isprime[j] = False