|
|
|
Sieve of Eratosthenes
-1
An algorithm that returns prime numbers from 2 up to
def E_sieve(n):
A=[]
for p in range(2, n+1): # fils the list with numbers from 2 up to n
A.append(p)
for p in range(2, int(floor(n)-1)):
if A[p]!=0: # cheks if p had been eliminated in any of the previous passess
j=p*p
while j<=n-2:
A[j]=0 # marks element as eliminated
j+=p
# copying the remaining elements from list A into list L
i=0
L=[]
for p in range(2, n-1):
if A[p]!=0:
L.append(p)
i+=1
return L




There are currently no comments for this snippet.