I am getting time limit error

Scanner s = new Scanner(System.in);
int num = s.nextInt();
int[] arr = null;
arr = new int[num];
for (int i = 0; i < arr.length; i++) {
arr[i] = s.nextInt();
}
for (int i = 0; i < arr.length; i++) {
nthprime(arr[i]);
}

}

public static void nthprime(int n) {
	int num, count, i;
	num = 1;
	count = 0;

	while (count < n) {
		num = num + 1;
		for (i = 2; i <= num; i++) {
			if (num % i == 0) {
				break;
			}
		}
		if (i == num) {
			count = count + 1;
		}
	}
	System.out.println(num);
}

}

Hi @Anshuman-Behera-1168641663271515

You are getting time limit exceeded because the constraints of the questions are big. Try using a different approach such as Sieve of Eratosthenes.

Hi Anshuman,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.