Just to clarify :) This is part 2 of my previous question. I'm posting a new question because the previous one got a bit messy and since I'm new to Stack, I'm still learning how things work here.
After implementing the suggestions, my previous code started working but the problem of Time Limit Exceed started occurring. I've tried my best to reduce the code, but TLE is still occurring. Here is my new code:
from math import sqrt
test = int(input())
for i in range(test):
summ = 0
maxx = int(input())
if maxx==1:
summ = 0
elif maxx==2:
summ += 2
else:
summ = summ + 2
for x in range(3,maxx+1,2):
half = int(sqrt(x)) + 1
for y in range(3,half,2):
if x%y==0:
break
else:
summ = summ + x
print(summ)
This time the code is producing the correct result. I just want to know how can I make my code more efficient and reduce Time Limit?