One test case in failing (deepak and primes)

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

}

int main() {
int n;
cin>>n;

int p[500000];

for(long long int j=0;j<500000;j++){
	p[j]=0;
}

primesieve(p);

int arr[500000];

long long int j=1;

for(long long int i=0;i<=500000;i++){
	if(p[i]==1){
		arr[j]=i;
		j++;
	}
}

cout<<arr[n];

return 0;

}

hello @vanshit02

sieve size is not sufficinet .
find the value of 500 000th prime number and prepare ur sieve atleast upto that.

can you elaborate a bit why the size is not sufficient?

check the valuer of n. it is 500 000 that means they may u may need to print 500 000th prime number,
and to compute 500 000 thn prime number ur sieve size must be atleast utpo 500 000th prime number and 500 000th prime number is not 500 000 , it is greater than that

ok…makes sense…got it.

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.