Prateek love candy


it is not printinig positions after 4?
why so?

you are initializing the numbers as the prime number in sieve function using the following way:-
for(int i=3;ii<=n;i+=2)
p[i]=1;
which is wrong because you are missing many numbers, so your condition should be simple i<=n not i
i<=n.
so modify you as following:-
for(int i=3;i<=n;i+=2)
p[i]=1;

A) i have taken sieve approach…even if i start from i the numbers less than i*i would be cut by smaller number.

B) i have evne tried i instead of i*i…still not working?

No, It is working fine by making this change only.
I think you are providing wrong input, Your first input should be the number of test cases t and then next t lines will the query whose answer you will have to evaluate.