Skip to content

Instantly share code, notes, and snippets.

@BedirYilmaz
Created October 23, 2016 18:20
Show Gist options
  • Save BedirYilmaz/b81cf92c08ae466cb2a7674f4d4af96c to your computer and use it in GitHub Desktop.
Save BedirYilmaz/b81cf92c08ae466cb2a7674f4d4af96c to your computer and use it in GitHub Desktop.
Sum all primes until a certain number
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