Why My Code is giving me TLE Error for Prateek Loves Candy . After Submission it is giving me to think more optimized Solution but i am not able to figure out which part of my code is taking time in compilation
public class PrateekLovesCandy {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t>0)
{
boolean flag = true;
int countern = 1;
int num = 2;
int n = scn.nextInt();
while(countern<=n)
{
flag = true;
for(int i = 2 ; i<num;i++)
{
if(num % i == 0)
{
flag = false;
}
}
if(flag == true)
{
//System.out.println("PRIME : "+ num);
countern++;
num++;
}
else
{
//System.out.println("NOT PRIME : "+ num);
num++;
}
}
System.out.println(num-1);
t--;
}
scn.close();
}
}