Prateek Loves Candy . Please help me find error in this code it is giving TLE at Test Case 0

import java.util.*;

public class Main {

public static void main(String args[]) {

	Scanner scan = new Scanner(System.in);
	int T = scan.nextInt();
	int[] arr = new int[1000000];
	
	for(int i = 0; i< arr.length; i++){
		arr[i] = 1;
	}

	arr[0] = arr[1] = 0;

	for(int i =2; i< Math.sqrt(arr.length); i++){
		if(arr[i] == 1){
			for(int j = i*i; j<arr.length; j += i){
				arr[j] = 0;
			}
		}
	}


	for(int ia = 1; ia<=T; ia++){
		int N = scan.nextInt();
		int count = 0;
		for(int j = 0; j<arr.length; j++){
			if(count == N){
				System.out.println(j - 1);
				break;
			}
			if(arr[j] == 1){
				count++;
			}
		}
	}

}

}

You misinterpreted the question. The total cost for all the candies is the nth prime number.

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.