Sieve of Pritchard: Difference between revisions
→Python: Started by noticing that the max() should be a min(), then noticed there was some other places that could be made more efficient.
(→C#: Small shortcut, explanation expanded) |
(→Python: Started by noticing that the max() should be a min(), then noticed there was some other places that could be made more efficient.) |
||
Line 185:
while prime * prime <= limit:
if steplength < limit:
nlimit = min(prime * steplength, limit)
for w in list(members):
n = w + steplength
while n <=
members.add(n)
n += steplength
steplength =
for w in sorted(members):
n = prime * w
if n
primes.append(prime)
prime = 3 if prime == 2 else min(m for m in members if m > 1)
if steplength < limit:
for w in
n = w + steplength
if n > limit: break # no use etc...
while n <= limit:
members.add(n)
n += steplength
return primes + sorted(members)[1:]
print(pritchard(150))
|