fork download
  1. import numpy as np
  2. from time import time
  3.  
  4. _start_time_ = time()
  5.  
  6. _arr_ = np.empty(1_000_000, dtype=np.int32)
  7. _arr_[0] = 2
  8. _count_ = 1
  9.  
  10.  
  11. def init_primes():
  12. global _arr_
  13. global _count_
  14.  
  15. for n in range(3, 100_000, 2):
  16. is_prime = True
  17.  
  18. for i in range(_count_):
  19. p = _arr_[i]
  20.  
  21. if p * p > n:
  22. break
  23. elif n % p == 0:
  24. is_prime = False
  25. break
  26.  
  27. if is_prime:
  28. _arr_[_count_] = n
  29. _count_ += 1
  30.  
  31.  
  32. if __name__ == '__main__':
  33. init_primes()
  34.  
  35. print(_count_)
  36.  
  37. print('\nElapsed time: {:.2f}s'.format(time() - _start_time_), end='')
  38.  
Success #stdin #stdout 4.56s 27016KB
stdin
Standard input is empty
stdout
9592

Elapsed time: 4.38s