Why is it giving tle?

You should make a vector which should store the sum of the numbers from 1 to 10^6

sir please explain the problem in that code…

You are only considering the fact if number is prime then print ans else print -1.