Last active
October 21, 2019 17:44
-
-
Save voith/6e89d642ef249986fa450bf0337f1d8e to your computer and use it in GitHub Desktop.
sum of first 2000000 prime numbers
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
""" | |
sum of first 2000000 prime numbers | |
output: 142913828922 | |
""" | |
num = 2000000 | |
sieve = [True] * num | |
sieve[0] = False | |
i = 2 | |
while (i * i <= num): | |
if sieve[i-1] == True: | |
for k in range(2 * i, num + 1, i): | |
sieve[k-1] = False | |
i += 1 | |
print(sum(i for i, value in enumerate(sieve, 1) if value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment