euler

git clone git://git.codymlewis.com/euler.git
Log | Files | Refs

commit ac8724a43efd29683f5352f24416ac76360826b9
parent f3fee581272acaf610fcd5589ea5e3e25ab8c1d3
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Sun, 18 Nov 2018 18:46:16 +1100

Solution to problem 10

Diffstat:
ATen.py | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)

diff --git a/Ten.py b/Ten.py @@ -0,0 +1,28 @@ +import math +''' +The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. + +Find the sum of all the primes below two million. +''' + + +def sum_primes(n): + i = prime_sum = 2 + while i < n: + if is_prime(i): + prime_sum += i + i += 1 + return prime_sum + + +def is_prime(n): + for i in range(2, int(math.ceil(math.sqrt(n))) + 1): + if (n % i) == 0: + return False + return True + + +if __name__ == "__main__": + LIMIT = 2_000_000 + print("Started finding sum...") + print(f"The sum of primes below {LIMIT} is {sum_primes(LIMIT)}")