fork download
  1. from math import *
  2. prime = [1] * (10 ** 6 + 1 )
  3. def sang():
  4. prime[0] = 0
  5. prime[1] = 0
  6. for i in range(2 , isqrt((10 ** 6 + 1 )) + 1):
  7. if(prime[i]):
  8. for j in range(i * i , (10 ** 6 + 1 ), i):
  9. prime[j] = 0
  10.  
  11. if __name__ == '__main__':
  12. sang()
  13. F = [0] * (10 ** 6 + 1 )
  14. F[0] = 0
  15. F[1] = 0
  16. dem = 0
  17. for i in range(2 , (10 ** 6 + 1 )):
  18. if(prime[i]):
  19. dem += 1
  20. F[i] = dem
  21. t = int(input())
  22. for i in range(t):
  23. x = int(input())
  24. print(F[x])
  25.  
Success #stdin #stdout 0.43s 27960KB
stdin
5
39
68
26
87
6
stdout
12
19
9
23
3