Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import math
  2. import itertools
  3. counter = 0
  4. counters = 0
  5. for i in itertools.count():
  6. # ignore numbers smaller than 2 because they are not prime
  7. if i < 2:
  8. continue
  9. # The most important change: if you don't reset your counter to zero all but the first prime number will not be prime because your counter is allways greater than zero
  10. counter = 0
  11. for n in range (2, math.ceil(i/2)+1):
  12. if i%n == 0:
  13. counter = 1
  14. # if you find out your number is not prime, break the loop to save calculation time
  15. break;
  16.  
  17. if counter == 0:
  18. counters+=1
  19. else:
  20. pass
  21. if counters == 10001:
  22. break
  23. print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement