I have tried my best to optimize the code ,but still failed to get pass through 1 test case . Can you please guide me a better approach to optimize this code
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in) ;
int n = scan.nextInt() ;
while(n-- > 0){
int choco = scan.nextInt() ;
int count = 0 ;
int latest = 0 ;
boolean isPrime ;
for(int i =2 ; count != choco ; i++){
isPrime = true ;
for(int j = 2 ;j <= Math.sqrt(i) ; j++){
if(i % j == 0){
isPrime =false ;
break ;
}
}
if(isPrime){
count ++ ;
if(count == choco){
latest = i ;
break ;
}
}
}
System.out.println(latest) ;
}
}
}
Compiler is showing that i have used brute force approach,I don’t know what is brute force ,Can you explain me what is brute force and also which approach is better than brute force?