Skip to content

Instantly share code, notes, and snippets.

@erfan-sahraei
Created July 15, 2020 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erfan-sahraei/a522c96e15869657cd65bd0f2551d3ae to your computer and use it in GitHub Desktop.
Save erfan-sahraei/a522c96e15869657cd65bd0f2551d3ae to your computer and use it in GitHub Desktop.
def sumOfPrimes(n):
prime = [True] * (n + 1)
p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1
sum = 0
for i in range (2, n + 1):
if(prime[i]):
sum += i
return sum
n = 2000000
print (f"sum is:{sumOfPrimes(n)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment