Deepak and primes. shows run time error. whats wrong?

#include
using namespace std;
#define ll long long

ll prime(ll n)
{ ll x=5000001;
ll arr[x]={0};
arr[0]=0;
arr[1]=0;
arr[2]=1;
for(ll i=3;i<x;i+=2)
arr[i]=1;

  if(n==1)
  return 2;

  ll cnt=1;
ll i=3;
while(cnt<n)
 {   
      for(ll j=i*i;j<x;j+=2*i)
         arr[j]=0;

    if(arr[i])
    cnt++;

    i+=2;
 }  

return i-2;

}
int main() {
ll n;
cin>>n;
cout<<prime(n);

return 0;

}

hey @ankityadav943, please share the code saved in coding blocks ide

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.