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 checks to see if a number is a prime in osqrtn a number is prime if it has exactly two factors 1 and itself returns boolean representing primality of given number num i e if the result is true then the number is indeed prime else it is not isprime2 true isprime3 true isprime27 false isprime2999 true isprime0 false isprime1 false 2 and 3 are primes negatives 0 1 all even numbers all multiples of 3 are not primes all primes number are in format of 6k 1 returns the sum of all the primes below n solution1000 76127 solution5000 1548136 solution10000 5736396 solution7 10 checks to see if a number is a prime in o sqrt n a number is prime if it has exactly two factors 1 and itself returns boolean representing primality of given number num i e if the result is true then the number is indeed prime else it is not is_prime 2 true is_prime 3 true is_prime 27 false is_prime 2999 true is_prime 0 false is_prime 1 false 2 and 3 are primes negatives 0 1 all even numbers all multiples of 3 are not primes all primes number are in format of 6k 1 returns the sum of all the primes below n solution 1000 76127 solution 5000 1548136 solution 10000 5736396 solution 7 10
import math


def is_prime(number: int) -> bool:
    

    if 1 < number < 4:
        
        return True
    elif number < 2 or number % 2 == 0 or number % 3 == 0:
        
        return False

    
    for i in range(5, int(math.sqrt(number) + 1), 6):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True


def solution(n: int = 2000000) -> int:
    

    return sum(num for num in range(3, n, 2) if is_prime(num)) + 2 if n > 2 else 0


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