Run time error on Submission

My code is running perfectly when I compile it or when I try run it on eclipse but shows run time error on submission

Q- Prateek’s Candy Challenge

	Scanner scn = new Scanner(System.in);
	int n = scn.nextInt();
	int[] prime;
	int[] b;
	b = new int[n];
	for(int a=0;a<n;a++){
		b[a] = scn.nextInt();
	}
	prime = new int[10000];
	int i = 1, flag ;
	for(int j = 2; j<=10000; j++){
		flag = 0;
		for(int k=2; k<j; k++){
			if(j%k==0){
				flag=1;
			}
		}if(flag==0){
			prime[i]=j;
			i++;
		}
	}
	for(int x = 0;x<n;x++){
	System.out.println(prime[b[x]]);
	}	

This is the core code

@satwik7142
You are supposed to use the prime seive optimisation technique (sieve of eratosthenes). Also make sure that you execute the primeseive function that you will make before the test cases only to prevent TLE.

Precompute the prime numbers using sieve technique.

In the sieve technique where you create a boolean array of b+1 size.

And start from the first prime number i.e. 2. Take its square(4) and increment it by the number you took (i.e. 4,6,8,10 and so on). Mark all these as false since they cannot be primes.

Now take the next unmarked number, 3. And mark 9,12,15 and so as false. Similarly do it for 4. 16,20,24 and so on as false.

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.