前六个质数是2,3,5,7,11和13,其中第6个是13.
第10001个质数是多少?
public class Test {
static boolean is_odd(long n){
if(n ==2 || n == 3){
return true;
}
if(n%2 == 0){
return false;
}
long i ;
for(i = 3; i < Math.sqrt(n)+1 ; i++){
if(n%i == 0 ){
return false;
}
}
return true;
}
public static void main(String[] args) {
int n = 10001;
int count = 0 ;
for(int i = 2 ;;i++){
if(is_odd(i)){
count ++;
}
if(count == n){
System.out.println("第"+ n + "项素数为:"+i);
break;
}
}
}
}