You are viewing a single comment's thread. Return to all comments →
#!/bin/python3 import sys limit = 1000000 suml = [0] * limit a = [True] * limit a[0] = a[1] = False for i, isprime in enumerate(a): if isprime: suml[i] = suml[i-1] + i for n in range(i*i, limit, i): a[n] = False else: suml[i] = suml[i-1] t = int(input().strip()) for a0 in range(t): n = int(input().strip()) print(suml[n])
This is python implementation of sieve of eratosthenes with a list that keeps sum of all prime numbers till n, at index n. Passes all test cases.
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #10: Summation of primes
You are viewing a single comment's thread. Return to all comments →
This is python implementation of sieve of eratosthenes with a list that keeps sum of all prime numbers till n, at index n. Passes all test cases.