Parteek loves candy... :)

//// time limit reached

You have to use n as N=1000000, also you have to call primeseive function before the testcase, but in your code you have used it for every test case. Plz modify your code accordingly.