in java crux course, prateel loves candy question :
i tried to solve it as follows but getting TLE on submitting while with custom input its working fine …
please help …
CODE -
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int i,n,p,count,flag;
int amount =0;
int cases = sc.nextInt();
for(int j=1; j<=cases; j++){
n=sc.nextInt();
p=2;
i=1;
while(i<=n){
flag=1;
for(count=2;count<=p-1;count++){
if(p%count==0){
flag=0;
break;
}
}
if(flag==1){
amount = p;
i++;
}
p++;
}
System.out.println(amount);
}
}
}