Created
July 15, 2020 11:25
-
-
Save erfan-sahraei/a522c96e15869657cd65bd0f2551d3ae to your computer and use it in GitHub Desktop.
This file contains 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 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