Deepak and Primes - Wrong Answer

#include
#define ll long long
using namespace std;

void seive(int a[], int n)
{
//special
a[2] = a[1] = 1;

//set all odds to 1
for(ll i=3; i<n; i=i+2)
{
	a[i] = 1;
}

for(ll i = 3; i<n; i=i+2)
{
	if(i == 1){
		for(ll j=i*i; j<n; j+=j){
			a[j] = 0;
		}
	}
}

}

int main() {
int max = 5000000;
int n;
cin>>n;

int a[max] = {0};

seive(a,max);

int count = 1;
while(n>0)
{
	if(a[count] == 1){
		n--;
	}
	
	count++;
}

cout<<count;


return 0;

}

@abhishekchoudhary
hello abhishek ,
declare ur sieve size greater than 5000000th prime number
image

I tried this, but it still doesn’t work.

@abhishekchoudhary
In ur code u are declaring sieve size as 5000000 but prime number corresponding to 5000000 can be greter than that therefore u need to change ur size.
first check 5000000th prime number and then declare ur sieve size greater than that.

I’ve made some changes. It is still not working.

#include
#define ll long long
using namespace std;

void seive(ll a[], ll n)
{
//special
a[2] = a[1] = 1;

//set all odds to 1
for(ll i=3; i<n; i=i+2)
{
	a[i] = 1;
}

for(ll i = 3; i<n; i=i+2)
{
	if(a[i] == 1){
		for(ll j=i*i; j<n; j+=i)
		{
			//cout<<"j "<<j<<" ";
			a[j] = 0;
		}
		//cout<<endl;
	}
}

}

int main() {
ll max = 86028122;
//ll max = 100;
ll n;
cin>>n;

ll a[max] = {0};

seive(a,max);

//for(ll i = 2; i<100; i++)
//{
//	if(a[i] == 1){
//		cout<<i<<" ";
//	}
//}
//cout<<endl;

ll count = 1;
while(n>0)
{
	if(a[count] == 1){
		n--;
	}
	
	count++;
}

cout<<count;


return 0;

}

Fixed it.
Here is the working code.

#include
#define ll long long
using namespace std;

void seive(ll a[], ll n)
{
//special
a[2] = a[1] = 1;

//set all odds to 1
for(ll i=3; i<n; i=i+2)
{
	a[i] = 1;
}

for(ll i = 3; i<n; i=i+2)
{
	if(a[i] == 1){
		for(ll j=i*i; j<n; j+=i)
		{
			//cout<<"j "<<j<<" ";
			a[j] = 0;
		}
		//cout<<endl;
	}
}

}

int main() {
ll max = 86028123;
//ll max = 100;
ll n;
cin>>n;

ll a[max] = {0};

seive(a,max);

//for(ll i = 2; i<100; i++)
//{
//	if(a[i] == 1){
//		cout<<i<<" ";
//	}
//}
//cout<<endl;

ll count = 1;
while(n>0)
{
	//cout<<"count "<<count<<" a[count] "<<a[count]<<endl;
	if(a[count+1] == 1){
		n--;
	}
	
	count++;
}

cout<<count;

return 0;

}