首页 > 其他 > 详细

(Problem 7)10001st prime

时间:2014-02-11 22:09:10      阅读:426      评论:0      收藏:0      [点我收藏+]

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?

bubuko.com,布布扣
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
  
int prim(int n)
{
   int i;
   for(i=2; i*i<=n; i++)
   {
      if(n%i==0)
        return 0;
   }
   return 1;
}
  
void solve(int n)
{
  int i=2;
  int count=0;
  while(1)
  {
     if(prim(i))
     { 
       count++;
       if(count==n)
         break;
     }
     i++;
  }
  printf("%d\n",i);
}
  
  
int main()
{
  int n=10001;
  solve(n);
  return 0;
}
bubuko.com,布布扣
Answer:
25164150

(Problem 7)10001st prime

原文:http://www.cnblogs.com/acutus/p/3544518.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!