(prateek loves candy problem )got 4 out of 5 test cases correct , i am getting a TLE in one , need help not able to find my mistake

#include
using namespace std;
void primesieve(long long int a[])
{
a[0]=1;
a[1]=1;
a[2]=0;
for(long long int i=3;i<1000000;++i)
{
if(i%2==0)
{
a[i]=1;
}}
for(long long int i=3;i<1000000;i=i+2)
{ if(a[i]==0)
{
for(long long int j=i*i;j<1000000;j=j+i)
{
a[j]=1;
}
}

}

}
int main() {
long long int k,ans;
long long int arr[1000000]={0};
long long int t;
cin>>t;
primesieve(arr);
while(t–)
{
cin>>k;
for(long long int i=2;k>0;++i)
{
if(arr[i]==0)
{ --k;
ans=i; }

}
cout<<ans<<endl;
}
return 0;
}

and also, in my sieve function, i have marked all the prime numbers as 0 instead of 1

please save your code at https://ide.codingblocks.com/
and send the link

  1. paste your code at https://ide.codingblocks.com/
  2. click on file->save
    after that a link will be generated at top
  3. now share that link

where should i share it?

obviously share it here

Your approach will give tle
use this approach

Reference 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.