Problem 7
28 December 2001
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 10001st prime number?
Answer: | 104743 |
#include
#include
int primer(long int n)
{
int flag=1;
long int i;
for(i=2;i<=sqrt(n)&&flag==1;i++)
if(n%i==0)
flag=0;
return (flag);
}
int main(void)
{
long int a[10001],num=3,i=1;/*忽略了2,这种情况,第10000,就是所求*/
while(i<=10000)
{
if(primer(num))
{
a[i]=num;
i++;
}
num=num+2;
}
printf("%ld\n",a[10000]);
return 0;
}
0 评论:
发表评论