I am trying to solve the 10 problem in the Project Euler. It consists on finding the sum of all the primes below two million. I wrote the following code based on the Sieve of Eratosthenes.
import time
t0 = time.time()
n=200000
liste=list(range(2,n))
k=2
s=2
while k <=n:
liste=list(set(liste)-set(range(k,n,k)))
if liste!=[]:
k=min(liste)
s+=k
else:
break
print(s)
t1 = time.time()
total = t1-t0
print(total)
I tested the above code for n=200000, but it is too slow for n=2000000. I would be very thankful to get any help to improve this program.