TLE error in one testcase

how can i fix this TLE error . also is there any efficient way to find a value at paticular index while using prime seive.

#include
using namespace std;

void prime_sieve(int a[]){
for(long i=3;i<=1000000;i+=2){
a[i]=1;
}
for(long i=3;i<=1000000;i+=2){
if(a[i]==1){
for(long j=i*i;j<=1000000;j+=i){
a[j]=0;
}
}
}
a[2]=1;
a[1]=a[0]=0;
}
int main() {
int a[1000005]={0};
prime_sieve(a);
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int count_1=0;
int num=0;
while(count_1<n){
if(a[num]==1){
count_1++;
}
num++;
}
cout<<num-1<<endl;
}
return 0;
}

@asifkarim073 instead of running a while loop to count n prime numbers store all your prime numbers in a vector while using sieve then for every test case prime_vector[n-1] will be your answer.