Code is getting partial submission!

here is the code for Deepak and primes:
#include<bits/stdc++.h>
#define MAX 1000000
typedef unsigned long ll;
using namespace std;
void sieve_prime(ll *arr,ll n){
//first marking all odd as prime number
for(ll i=3;i<=MAX;i+=2)
arr[i]=1;

//applying sieve
for(ll i=3;i<=MAX;i+=2){
	if(arr[i]==1){
		for(ll j=i*i;j<=MAX;j+=i){
			arr[j]=0;
		}
	}
}
//special case
arr[0]=0;
arr[1]=0;
arr[2]=1;

int res=0,i=0;
while(n>0){
	if(arr[i]==1){
	    res=i;
	    //cout<<i<<" ";
	    n--;
	}
	i++;
}
cout<<res<<endl;

}
int main() {
ll n;
cin>>n;
ll arr[MAX]={0};
sieve_prime(arr,n);

return 0;

}

hello @pks101295
check value of 5000 000th prime number from internet and declare ur sieve array size greater than that

Hey,
I did but now it is showing Seg. fault!!!

#include<bits/stdc++.h>
typedef unsigned long long int ll;
using namespace std;
unsigned long long int MAX= 5000000;

void sieve_prime(ll *arr,ll n){
	//first marking all odd as prime number
	for(ll i=3;i<=MAX;i+=2)
	   arr[i]=1;
 
	//applying sieve
	for(ll i=3;i<=MAX;i+=2){
		if(arr[i]==1){
			for(ll j=i*i;j<=MAX;j+=i){
				arr[j]=0;
			}
		}
	}
	//special case
	arr[0]=0;
	arr[1]=0;
	arr[2]=1;
 
	ll i=0,counter=0;
    for(i=0;i<=MAX;i++){
		if(arr[i]==1)
		     {
				 counter++;
				 if(counter==n)
				   {
					   cout<<i<<endl;
				        break;
				   }
			 }			
	}
	
	
}
int main() {
	ll n;
	cin>>n;
	ll arr[MAX]={0};
	sieve_prime(arr,n);
	cout<<endl;
	return 0;
}

still ur sieve size is not sufficient to accomodate 5000 000th prime number.

check this code-> https://ide.codingblocks.com/s/238861

also there is some issue with the checker,it is showing run error for every solution.


still 5 test cases passed out of 6.
image

… … …

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.