Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- import itertools
- counter = 0
- counters = 0
- for i in itertools.count():
- # ignore numbers smaller than 2 because they are not prime
- if i < 2:
- continue
- # 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
- counter = 0
- for n in range (2, math.ceil(i/2)+1):
- if i%n == 0:
- counter = 1
- # if you find out your number is not prime, break the loop to save calculation time
- break;
- if counter == 0:
- counters+=1
- else:
- pass
- if counters == 10001:
- break
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement