Not coming out of the loop

Here is my code you can check once, I created a prime sieve and tried to increase count each time we encounter an odd number and finally print the value of loop counter as the answer to this problem.

I guess my code runs for much longer than it actually should. There is a break statement when count == n but still the loop continues to run.

Please correct me where I am wrong.

hello @righley
ur code is not completely correct.
a) first of all build sieve upto 10^6 .

b) store all prime numbers upto 10^6 in some array .
c) u need answer t test cases but u r only considering one test case. use loop to read and print t test case.

#include <iostream>
#include <vector>
using namespace std;
#define MAX 10000000
vector<bool>isPrime (MAX,true);
unsigned primearray[5761459];


void gen_primes(){
    isPrime[0]=isPrime[1]=false;
    for(unsigned i=2;i*i<=MAX;i++){
        if(isPrime[i]){
            for(unsigned j=i;j*i<=MAX;j++) isPrime[i*j]=false;
        }
    }
    unsigned idx = 1;
    primearray[0]=2;

    for(int i=3;i<=MAX;i+=2){
        if(isPrime[i]){
            primearray[idx++]=i;
        }     
    }
}

int main(int argc, char const *argv[])
{

    gen_primes();

    int t;
    cin>>t;
    while(t--) {
        int n;
        cin>>n;
        cout<<primearray[n-1]<<endl;
    }
    return 0;
}


```

oh I completely overlooked the test cases part. Understood my mistake thank you!

Oh I completely overlood the number of test cases and understood my mistake, thank you. But is there a way I can do this without forming another array and manipulating the same array we made for prime sieve?

yeah u can use same isprime array intead of taking a seprate array of storing primes

okay got it, Thank you!