project euler problem 10 https projecteuler netproblem10 summation of primes the sum of the primes below 10 is 2 3 5 7 17 find the sum of all the primes below two million references https en wikipedia orgwikiprimenumber https en wikipedia orgwikisieveoferatosthenes returns the sum of all the primes below n using sieve of eratosthenes the sieve of eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 million only for positive numbers solution1000 76127 solution5000 1548136 solution10000 5736396 solution7 10 solution7 1 doctest ellipsis traceback most recent call last typeerror float object cannot be interpreted as an integer solution7 doctest ellipsis traceback most recent call last indexerror list assignment index out of range solutionseven doctest ellipsis traceback most recent call last typeerror can only concatenate str not int to str returns the sum of all the primes below n using sieve of eratosthenes the sieve of eratosthenes is one of the most efficient ways to find all primes smaller than n when n is smaller than 10 million only for positive numbers solution 1000 76127 solution 5000 1548136 solution 10000 5736396 solution 7 10 solution 7 1 doctest ellipsis traceback most recent call last typeerror float object cannot be interpreted as an integer solution 7 doctest ellipsis traceback most recent call last indexerror list assignment index out of range solution seven doctest ellipsis traceback most recent call last typeerror can only concatenate str not int to str
def solution(n: int = 2000000) -> int:
    

    primality_list = [0 for i in range(n + 1)]
    primality_list[0] = 1
    primality_list[1] = 1

    for i in range(2, int(n**0.5) + 1):
        if primality_list[i] == 0:
            for j in range(i * i, n + 1, i):
                primality_list[j] = 1
    sum_of_primes = 0
    for i in range(n):
        if primality_list[i] == 0:
            sum_of_primes += i
    return sum_of_primes


if __name__ == "__main__":
    print(f"{solution() = }")