(Problem 7)10001st prime

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?

 1 #include <stdio.h>

 2 #include <string.h>

 3 #include <ctype.h>

 4 #include <math.h>

 5   

 6 int prim(int n)

 7 {

 8    int i;

 9    for(i=2; i*i<=n; i++)

10    {

11       if(n%i==0)

12         return 0;

13    }

14    return 1;

15 }

16   

17 void solve(int n)

18 {

19   int i=2;

20   int count=0;

21   while(1)

22   {

23      if(prim(i))

24      { 

25        count++;

26        if(count==n)

27          break;

28      }

29      i++;

30   }

31   printf("%d\n",i);

32 }

33   

34   

35 int main()

36 {

37   int n=10001;

38   solve(n);

39   return 0;

40 }

 

Answer:
104743

 

你可能感兴趣的:(Prim)