TLE IN FIRST CASE

public static int soe(boolean[] a, int n) {

	int c = 0;
	for (int i = 2; i < a.length; i++) {
		if (a[i]) {
			c++;
		}

		if (c == n) {
			return i;
		}
	}
	return n;

}

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int t = 0;
	if (sc.hasNext()) {
		t = sc.nextInt();
	}

	boolean[] a = new boolean[1_000_005];
	Arrays.fill(a, true);
	a[0] = false;
	a[1] = false;
	for (int i = 2; i * i < 1_000_005; i++) {
		if (a[i]) {
			for (int j = i * i; j < 1_000_005; j += i) {
				a[j] = false;
			}
		}
	}

	while (t-- != 0) {
		int n = sc.nextInt();
		System.out.println(soe(a, n));

	}

}

@arpit.jain22june
refer to this code here


use the sieve