Run time Error- Prateek loves candy

#include<iostream>
#include<vector>
using namespace std;
int a[10009]={0};
void prime(){
    a[0] = a[1] = 0;
    a[2] = 1;
    
    for(int i=3;i<=10009;i+=2){
        a[i] = 1;
    }
    
    for(int i=3;i<=10009;i+=2){
        if(a[i]){
            for(int j = i*i; j<=10009; j+=2*i){
                a[j] = 0;
            }
        }
    }
    return;
}



void check(int n){
   
   // int p[n];
    vector<int> v;
   
    for(int i=2;i<=10009;i++){
    if(a[i]){
        v.push_back(i);
         }
       
    }
    cout<<v[n-1]<<'\n';
  
    
}
int main() {
    int test;
     prime();
    cin>>test;
    while(test--){
        int n;
        cin>>n;
        check(n);
    }
	return 0;
}

Problem:
https://hack.codingblocks.com/contests/c/587/52

facing run time error, code working fine though.

@Khushboo can you look into it?

Hi Lakshay, since there are many big test cases in this problem, your code is not the optimal solution. I’ve made some changes to your code and now it’s working fine. Go through it and let me know if there are any doubts. You can refer to the code here: https://ide.codingblocks.com/s/60894.