fork download
  1. import math
  2. def primeList(n):
  3. plist = [2, 3]
  4. j = 3
  5. while len(plist) < n:
  6. j += 2
  7. lim = math.sqrt(j)
  8. for p in plist: # 100k primes: 3.75s vs 5.25 with while loop
  9. if p > lim: # and the setting of the flag,
  10. plist.append(j) # on ideone - dNLYD3
  11. break
  12. if j % p == 0:
  13. break
  14. return plist
  15. primeList(10000)
Success #stdin #stdout 0.25s 8832KB
stdin
Standard input is empty
stdout
Standard output is empty