def sieve(max):
    primes = []
    sieve = [True] * (max + 1)
    for n in range(2, int(max ** 0.5) + 1):
        if sieve[n]:
            sieve[n*n:max+1:n] = [False] * len(range(n*n, max+1, n))
    for n in range(2, max + 1):
        if sieve[n]:
            primes.append(n)
    return primes