Using System.currentTimeMillis(), i’ve got my time to be around 20ms still I am getting timelimit error, pls help!
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int r=1,i=2;
int m=0;
int n1=scan.nextInt();
while(r<=n1){
int n = scan.nextInt();
int count=n;
int arr[] = new int[1000001];
arr[0]=0;
arr[1]=0;
for(int k =2;k<1000001;k++){
arr[k]=1;}
while(i<=1000000){
m=0;
if(arr[i]==1){
for(int j=2;j*i<=1000000;j++){
if(arr[i*j]!=0)
arr[i*j]=0;
}
}
if(arr[i]==1){
m=i;
count–;
}
i++;
if(count==0)
break;
}
System.out.println(m);
i=2;
r++;
}
}
}