Created
October 23, 2016 18:20
-
-
Save BedirYilmaz/b81cf92c08ae466cb2a7674f4d4af96c to your computer and use it in GitHub Desktop.
Sum all primes until a certain number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sumPrimesErastothanesWay(n): | |
notprime = False | |
primemultiples = set() | |
sum = 0 | |
for x in range(2 , n): | |
if x in primemultiples: | |
notprime = True | |
if(notprime != True): | |
root = int(math.ceil(math.sqrt(x))) | |
for i in range (3, root): | |
if x%i == 0 and x != i: | |
notprime = True | |
break | |
for z in range(2*x , n, x): | |
primemultiples.add(z) | |
sum += x | |
notprime = False | |
return sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment