Skip to content

Commit a6c10de

Browse files
Merge pull request #679 from varsubham/patch-3
Updated sieve of erathostenes function
2 parents 7f7a169 + c483a01 commit a6c10de

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

primelib/primelib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,16 @@ def sieveEr(N):
100100
# precondition
101101
assert isinstance(N, int) and (N > 2), "'N' must been an int and > 2"
102102

103-
primes = [True for x in xrange(N + 1)]
103+
primes = [True for x in range(N + 1)]
104104

105-
for p in xrange(2, sqrt(N) + 1):
105+
for p in range(2, int(sqrt(N)) + 1):
106106
if (primes[p]):
107-
for i in xrange(p*p, N + 1, p):
107+
for i in range(p*p, N + 1, p):
108108
primes[i] = False
109-
109+
primes[0]=False
110+
primes[1]=False
110111
ret = []
111-
for p in xrange(N + 1):
112+
for p in range(N + 1):
112113
if primes[p]:
113114
ret.append(p)
114115

0 commit comments

Comments
 (0)