projectEuler pro7

Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?\

JAVA:

public class P007 {
public static void main(String[] args){
int num = 1;
for(int i =3 ;;i++){
if(isprime(i))
num++;
if(num==10001){
System.out.print(i);
break;
}
}
}
public static boolean isprime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
return true;
}
}

posted on 2013-10-09 21:37  Monster_Ch  阅读(144)  评论(0编辑  收藏  举报

导航