The fasted way to generate Prime number in Python can be:
importitertoolsdef erat2():
D = {}yield 2
for q initertools.islice(itertools.count(3), 0, None, 2):
p = D.pop(q, None)if p isNone:
D[q*q] = q
yield q
else:
x = p + q
while x in D ornot(x&1):
x += p
D[x] = p
The fasted way to generate Prime number in Python can be:
so that would give