Playing with Cards( In Stack ) problem

What is wrong with my code. It is not giving any output. Please Help.

Hi,

Check your prime sieve code. Initially all elements are considered to be prime. But you have initialised 0 to all numbers.

I am still not able to get it. Please help!!

try to submit this:

Now 2/3 test cases are passing and the 3rd test case is showing TLE.

Actually in your code of prime sieve the outer loop is for(int i=3;i<=100005;i+=2) but it should be
for(int i=3;i*i<=100005;i+=2)

It is still giving TLE

You are calling prime sieve again and again for every testcase. That is why, it is giving tle. You should precompute kth prime before queries.