i have tried this approach https://ide.codingblocks.com/s/146735
the code is working for lower test cases ,but not for higher value test cases , i don’t know why??
Prateek Loves Candy
import java.util.Scanner;
public class PrateekLovesCandy {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int k = 1; k <= t; k++) {
int n = sc.nextInt();
int prime = 0;
boolean status = true;
int x = 2;
for (int i = 1; i <= n;) {
for (int j = 2; j <= Math.sqrt(x); j++) {
if (x % j == 0) {
status = false;
break;
}
}
if (status) {
prime = x;
i++;
}
if (i != 2) {
x+=2;
}
else
x ++;
status = true;
}
System.out.println(prime);
}
}
}
this code is working for all test cases but a single test case is not running and showing time limit exceeded error.