Return to Snippet

Revision: 35141
at November 3, 2010 05:36 by Doctor_Who


Initial Code
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

Initial URL


Initial Description
Function (algorithm) that returns all prime numbers  up to n.

Initial Title
Sieve of Eratosthenes

Initial Tags
python

Initial Language
Python