Skip to content

Commit dece4c0

Browse files
authored
Create n_primes.py
1 parent eae4c21 commit dece4c0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

n_primes.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Eratosthenes application of sieve algorithm
2+
def eratosthenes2(n):
3+
multiples = set()
4+
for i in range(2, n+1):
5+
if i not in multiples:
6+
yield i
7+
multiples.update(range(i*i, n+1, i))
8+
9+
primes = list(eratosthenes2(4000000))

0 commit comments

Comments
 (0)