#10: Summation of primes | Ben Cunningham

#10: Summation of primes

Problem by Project Euler · on February 8, 2002

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Python

def is_prime(x):

    if x < 4:
        return True

    if x % 2 == 0:
        return False

    for fac in range(3, int(x ** (1/2.0)) + 1, 2):
        if x % fac == 0:
            return False

    return True
    
ans = 2
for n in range(3, 2000000, 2):
    if is_prime(n):
        ans += n
        
print(ans)
## 142913828922