Python solution using functions


#1
def sieve(self, A):
    numbers=list(range(1,A+1))
    prime=2
    
    def findnonprimes(current, prime):
        i=prime*prime
        while i < len(current):
            current[i-1]=0
            i+=prime
        if current[-1]==i:
            current[-1]=0
            
    def nextprime(current,prime):
        next=prime+1
        while next<len(current) and not current[next-1]:
            next+=1
            
        return next
        
    while(prime<=math.sqrt(A)+1):
        findnonprimes(numbers,prime)
        prime=nextprime(numbers,prime)
        
        
    return [num for num in numbers if num!=0 and num!=1]