Deepaks prime- getting wrong answer

similiar question was for prateeks candy, here I just increased the maximum value of array to 5000001, but it is accepting only 2 cases, can anybody help?

#include<bits/stdc++.h>
using namespace std;

int a[5000001]={0};
int prime[5000001];
void sieve(){
a[0]=0;
a[1]=0;
a[2]=1;
for(int i=3;ii<=5000001;i+=2){
a[i]=1;
}
for(int i=3;i
i<=5000001;i+=2){
if(a[i]){
for(int j=ii;j<=5000001;j+=2i){
a[j]=0;
}
}
}
int count=0;
for(int i=0;i<=5000001;i++){
if(a[i]){
prime[count]=i;
count++;
}
}
}
int main() {
sieve();
int index;
cin>>index;
cout<<prime[index-1]<<endl;
return 0;
}

@Himanish hey himanish this question is application of sieve of eratosthenes. So please apply prime sieve
here otherwise you will get time limit exceed error

I have applied optimised sieve in this question!

@Himanish hey himanish go and watch video of “optimization of sieve of eratosthenes” in your course content you will get idea how to apply prime sieve correctly in optimize ways

sir , same code was uploaded for prateek’s candy which needed optimised sieve, this has the same concept, still WA that is why I am asking.