Getting TLE and also wrong answer for small ranges

#include
#include
using namespace std;

void prime(int *p)
{

for(long long i=3;i<=1000005;i=i+2)
    p[i]=1;

for(long long i=3;i<=1000005;i=i+2)
{
	if(p[i]==1)
	    for(long long j=i*i;j<=1000005;j=j+i)
		    p[j]=0;
}	

p[0]=p[1]=0;
p[2]=1;

}

int main() {

int p[1000005]={0};
vector<int> isprime;
prime(p);

for(int i=2;i<=1000005;i++)
     if(p[i]==1)
	    isprime.push_back(i);
//Test Case Input
int x;
cin>>x;

while(x>0)
{
	//Taking Numbers Input for Getting Prime Values
	int a;
	cin>>a;
    cout<<isprime[a-1];

x–;
}

return 0;

}

make the p array as global variable

it still giving same error

it’s showing Runtime Error

sir, mene khud submit kia h !
100/100 score
#include<bits/stdc++.h>
using namespace std;

int p[1000007] = {0};

void prime()
{
p[0] = p[1] = 0;
p[2] = 1;

for (long long i = 3; i <= 1000005; i = i + 2)
    p[i] = 1;

for (long long i = 3; i <= 1000005; i = i + 2)
{
    if (p[i] == 1)
        for (long long j = i * i; j <= 1000005; j = j + i)
            p[j] = 0;
}

}

int main()
{

vector<int> isprime;
prime();

for (int i = 2; i <= 1000005; i++)
    if (p[i] == 1)
        isprime.push_back(i);
//Test Case Input
int x;
cin >> x;

while (x > 0)
{
    //Taking Numbers Input for Getting Prime Values
    int a;
    cin >> a;
    cout << isprime[a - 1]<<endl;
    x--;
}

return 0;

}

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.