ProjectEuler_P7

Question:

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?

 

C Code:

#include <stdio.h>

void main()
{
  int prim[10003];
  int no = 3;
  int i = 7;
  prim[1] = 2;
  prim[2] = 3;
  prim[3] = 5;
  while(no <= 10001)
  {
    for(;;i++)
    {
      int j = 1;
      int flag = 1;
      for(j = 1;j <= no;j++)
      {
        if(0 == i%prim[j])
        {
          flag = 0;
          break;
        }
      }
      if(flag)
      {
        no++;
        prim[no] = i;
        i++;
        break;
      }
    }
  }
  printf("%d\n",prim[10001]);
}

 

Answer:

104743

posted on 2014-04-23 19:35  楠哥1991  阅读(99)  评论(0编辑  收藏  举报

导航