runtime error on the question-"PRATEEK LOVES CANDY"

#include <bits/stdc++.h>
using namespace std;

void nthprime(int n,int x)
{
bool prime[n+1];
memset(prime, true, sizeof(prime)); //it initializes the prime array by true

for (int p=2; p*p<=n; p++)
{
    if (prime[p] == true)
    {
        for (int i=p*p; i<=n; i += p)
            prime[i] = false;
    }
}
prime[0]=false;
prime[1]=false;

    int pr[10000];
     int i=0;
     for (int p=1; p<=(n); p++){

   if (prime[p]){
      pr[i] = p;
      i++;}

}
cout<<pr[x-1]<<endl;
}

int main()
{
int t;
cin>>t;
while(t–){
int n;
cin>>n;
nthprime(n*n,n);
}
return 0;
}

Hey Shashank, as the constraints are large for input so take long long long int instead of int also you can’t do n*n as you are passing this in nthprime(n*n,n); as this will be a large number which results in run time error.