This is my Python3 code which solved the 10th problem of Project Euler. I haven't passed the last 2 time limit test cases.
def sieve_of_eratosthenes(n):
result = [True] * (n + 1)
result[0] = result[1] = False
for i in range(2, int(n**0.5)+1):
if result[i]:
for j in range(i*i, n+1, i):
result[j] = False
return [i for i in range(n+1) if result[i]]
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
result_arr = sieve_of_eratosthenes(n)
result = sum(result_arr)
print(result)
list
. Wow, that's a lot of 64-bit pointers! Prefer to use an array of unsigned char. Then you'll use less memory, and will be more cache friendly. Fewer cache misses means greater speed. \$\endgroup\$