Skip to content

Instantly share code, notes, and snippets.

@amirbakhtiari
Forked from ami-GS/fastPrime.py
Created February 6, 2014 09:30
Show Gist options
  • Save amirbakhtiari/8841060 to your computer and use it in GitHub Desktop.
Save amirbakhtiari/8841060 to your computer and use it in GitHub Desktop.
import sys
import time
s = time.time()
N = int(sys.argv[1])
prime = [True]*N
prime[0] = False
prime[1] = False
for i in range(2, int(N**0.5)):
if prime[i]:
for j in range(i*2, N, i):
prime[j] = False
ans = [i for i in range(N) if prime[i] == True]
print ans, len(ans), time.time()-s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment