My approach is not working

https://ide.codingblocks.com/s/258449. I was trying to make a vector in which I store the address which contains 1 .

hello @aryaman.kumar26
a)
image
this should be <= 1000000

b)
image
this if statement should be out of the for loop.

this is how ur sieve should look like->

a[0]=0,a[1]=0;
a[2]=1;
for(i=3;i<=1000000;i+=2)
a[i]=1;
for(i=3;i<=1000000;i+=2){
if(a[i]){
for(j=ii;j<1000000;j+=2i)
a[j]=0;
}
}

sir my sieve is fine but 0 is being stored in my vector

can you please if i print an item of my vector it is showing 0

https://ide.codingblocks.com/s/258892. Sir i have written a new code all test cases passes except 1 which was showing time limit exceeded.

store all ur prime numbers in some array and then use that array to print nt prime number in O(1)

but why my vector approach not working

yeah i have thought about it as well but when i will use the loop;
for(int i=0;i<10000000;i++){
if(a[i]==1){
b[i]=i;
this will lead to some elements of b array empty

for each each test case u r finding nth prime which is taking too much time.

what i m telling u to do ,is to compute all primes and store it in some array/vector
and then to print nth prime simply print element present at n-1 th index of the prime array

sir vo hito kiya tha uppar sabse upar wala link…vector se hi kiya tha but nhi ho rha

wo thik hai , mai ye keh raha hu ki tum saare prime number ko array/vector me store kar lo.
jaise ki 1st prime 2 ko index 0 pe
2nd prime 3 ko index 1 pe
3rd prime 5 ko index 2 pe
so on

aur jab tumhe nth prime print karna ho tab
simply is array kar n-1 th index pe jo value padhi ho wo print kar do .
isse time complexity reduce ho jayegi