题目
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?
找出第10001个质数。
前六个质数是2,3,5,7,11和13,其中第6个是13.
第10001个质数是多少?
解答:本题直接,循环判断就可以了。Java程序
public class N_7 {
public static int nPrime(int n){
int count=0;
int N=1;
while(count<=n)
{
boolean flag=true;
for(int i=2;i<=Math.sqrt(N);i++)
{
if(N%i==0)
{
flag=false;
break;
}
}
if(flag)
{
count++;
}
N++;
}
return N-1;
}
public static void main(String []args)
{
System.out.println(nPrime(10001));
}
}
运行结果:104743