Restore a sequence

please help me figure out I am getting the wrong answer . here is the link to my solution. Please someone help me.

In this problem, We require at least 100000 prime numbers according to the given constraints. In your solution, it is not generating that much amount of primes. So, for this reason, you are getting WA. Try to generate more Primes. I am sure it will definitely work for you.

you can go through my code :

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

int A[100000];
//function to find out prime numbers till n.
void P(long long int n)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));

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

}
int main() {
P(1299720);
// your code goes here
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int arr[n];
int C[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
C[i]=A[i];
}

    for(int i=0;i<n;i++)
    {
        if(arr[i]!=i+1)
        {
            C[i]=C[arr[i]-1];
        }
    }
    for(int i=0;i<n;i++)
    cout<<C[i]<<" ";
    cout<<endl;
}
return 0;

}