zoukankan      html  css  js  c++  java
  • 35.大质数

    时间限制: 1 s

     空间限制: 1000 KB

     题目等级 : 黄金 Gold

    题解

    题目描述 Description

    小明因为没做作业而被数学老师罚站,之后数学老师要他回家把第n个质数找出来。(1<=n<=100000)

    老师随机写了几个数,交给了小明。小明百度找了很久,都没能解决。现在交给聪明的你。请你帮忙!

    ————————————————————————————————————————————

    简单描述:把第n个质数找出来。

    输入描述 Input Description

    一个正整数n

    1<=n<=100000)

    输出描述 Output Description

    n个质数。

    (第1个质数为2,第2个质数为3。)

    样例输入 Sample Input

    样例1

    2

    样例2

    65

    样例3

    20133

    样例输出 Sample Output

    样例1

    3

    样例2

    313

    样例3

    226381

    数据范围及提示 Data Size & Hint

    有大数据等着你,小心超时,不许交表哦。

    1<=n<=100000)

     

    代码:

    #include

    #include

    using namespace std;

    #include

    int main()

    {

           int n;

           cin>>n;

           int t=0;

           for(long long i=2;;++i)

           {

                  int flag=0;

                  for(int j=2;j<=sqrt(i);++j)

                  {

                         if(i%j==0)

                         {

                                flag++;

                                break;

                         }

                  }

                  if(flag==0) t++;

                  if(t==n) {

                         printf("%lld",i);

                         return 0;

                  }

           }

           return 0;

    }

  • 相关阅读:
    How to alter department in PMS system
    Can't create new folder in windows7
    calculate fraction by oracle
    Long Wei information technology development Limited by Share Ltd interview summary.
    ORACLE BACKUP AND RECOVERY
    DESCRIBE:When you mouse click right-side is open an application and click left-side is attribution.
    ORACLE_TO_CHAR Function
    电脑BOIS设置
    JSP点击表头排序
    jsp+js实现可排序表格
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290452.html
Copyright © 2011-2022 走看看