Skip to content

Instantly share code, notes, and snippets.

@voith
Last active October 21, 2019 17:44
Show Gist options
  • Save voith/6e89d642ef249986fa450bf0337f1d8e to your computer and use it in GitHub Desktop.
Save voith/6e89d642ef249986fa450bf0337f1d8e to your computer and use it in GitHub Desktop.
sum of first 2000000 prime numbers
"""
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