How to solve tle in last case

#include
using namespace std;
#define ll long long

void prime_sieve(int p[]){
for(ll i=3;i<1000000;i+=2){
p[i]=1;
}
for(ll i=3;i<1000000;i+=2){
if(p[i]==1){
for(ll j=i*i;j<1000000;j+=i){
p[j]=0;
}
}
}
p[0]=p[1]=0;
p[2]=1;
}

int main() {
int t;
int p[1000000]={0};
prime_sieve§;
cin>>t;
while(t–){
ll n;
cin>>n;
ll cnt=0;
while(n>0){
if(p[cnt]==1){
cnt++;
n–;
}
else{
cnt++;
}
}
cout<<cnt-1<<endl;
}
return 0;
}

you need to construct a prime array such that ith index of that array points to the i+1th prime this way you’ll be able to answer each query in O(1)
Code adjusted accordingly: