fork download
  1. def sieve(N):
  2. M = (N-3)//2+1
  3. n = int(N**0.5)
  4. P = [3,5,7,0,11,13,0,17,19,0,23,0,0,29,31,0,0,37,0,41,43,0,47,
  5. 0,0,53,0,0,59,61,0,0,67,0,71,73,0,0,79,0,83,0,0,89,0,0,0,
  6. 97,0,101,103,0,107,109,0,113,0,0,0,121,0,0,127,0,131,0,0,
  7. 137,139,0,143,0,0,149,151,0,0,157,0,0,163,0,167,169,0,173,
  8. 0,0,179,181,0,0,187,0,191,193,0,197,199,0,0,0,0,209]+[0]*(M-105)
  9. G = (10,2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,8,6,4,6,2,4,6,2,6,6,4,2,4,6,2,6,4,2,4,2,10,2)
  10. last = 210*(N//210)+1
  11. for w in range(211,last,210):
  12. P[(w-3)//2]=1
  13. x = w
  14. for g in G:
  15. x+=g
  16. P[(x-3)//2]=1
  17. for g in G:
  18. P[(last-3)//2]=1
  19. last+=g
  20. if last > N:
  21. break
  22. for i in range(11,n+1,2):
  23. if P[(i-3)//2]:
  24. for j in range((i**2-3)//2,M-1,i):
  25. P[j]=0
  26. return [2]+[2*i+3 for i in range(len(P)) if P[i]]
Success #stdin #stdout 0.03s 44632KB
stdin
Standard input is empty
stdout
Standard output is empty