Time Limit Exceed

Scanner obj = new Scanner(System.in);
int t = obj.nextInt();

    if(t<=10000){
        for(int i=1; i<=t; i++){
            int n = obj.nextInt();
            if(n==1){
                System.out.println("2");
            }else if(n>1){
                int k=0, count =1;
                for(int m=3; m<=Integer.MAX_VALUE; m++){
                    for(int j=2;j<m; j++){
                        k=m%j;
                        if(k==0){
                            break;
                        }
                    }if(k!=0){
                        count+=1;
                        if(count==n){
                            System.out.println(m);
                            break;
                        }
                    }
                }
            }
        }
    }

see you are using bruteforce technique…you need to precompute the prime numbers using seive and do it outside the testcases loop…then when the user queries some value of n just return the ans…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.