zoukankan      html  css  js  c++  java
  • (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

     

  • 相关阅读:
    面试常见问题
    Servlet上传下载
    Java五大框架
    Jquery
    JavaEE
    Html学习
    JavaSE高级
    面向过程基础
    Java开发软件安装及配置
    JAVA的类加载机制和Class类
  • 原文地址:https://www.cnblogs.com/cpoint/p/3367347.html
Copyright © 2011-2022 走看看