target=2000000 d=[0]*target n=2 while n<target: for i in range(n+n,target,n): d[i]+=1 n+=1 while n<target and d[n]>0: n+=1 print sum(k for k in range(target) if d[k]==0)-1