import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while(t>0){
int N,i,j,root,value;
int total=0;
N=input.nextInt();
for(i=2;i>0;i++) {
if(i%2==0&&i>3) {}
else {
root=(int)Math.sqrt(i);
value=1;
for(j=2;j<=root;j++) {
if(i%j==0) {
value=0;
break;
}
}
if(value==1) {
++total;
if(total==N){
System.out.println(i);
break;
}
}
}
}
t–;
}
}
}
Test case 0 ,time limit exceed .rest all test case correct. and what sould be the condition for i in for loop
@KUNAL.SHARMA5724510,
You are supposed to use the prime seive optimisation technique (sieve of eratosthenes). Also make sure that you execute the primeseive function that you will make before the test cases only to prevent TLE.
Precompute the prime numbers using sieve technique.
In the sieve technique where you create a boolean array of b+1 size.
And start from the first prime number i.e. 2. Take its square(4) and increment it by the number you took (i.e. 4,6,8,10 and so on). Mark all these as false since they cannot be primes.
Now take the next unmarked number, 3. And mark 9,12,15 and so as false. Similarly do it for 4. 16,20,24 and so on as false.
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.