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;ii<=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;
}