TLE for last test case

#include
using namespace std;

#define ll long long int

void sieve(ll a[], ll b[])
{
for(ll i=3;i<=100000;i+=2)
{
a[i]=1;
}
for(ll i=3;i<=100000;i+=2)
{
if(a[i]==1)
{
for(ll j=i*i;j<=100000;j+=i)
{
a[j]=0;
}
}
}
a[0]=a[1]=0;
a[2]=1;
ll k=1;
for(ll i=2;i<=100000;i++)
{
if(a[i]==1)
{
b[k]=i;
if(k==1000000)
{
break;
}
k++;

	}
}	

}

int main() {
int t;
cin>>t;
while(t–){
ll n;
cin>>n;
ll a[100000]={};
ll b[100000]={};
sieve(a,b);
cout<<b[n]<<endl;
}
return 0;
}

Hi @tusharnitharwal
In in your code for each test case you are again and again computing prime numbers upto 100000 that is why it is giving TLE. To avoid this what you can do is call seive function one time before while loop, and then for each test case just print b[n].

Here is your corrected code :

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.