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;

    }

  • 相关阅读:
    哈尔滨理工大学软件与微电子学院第八届程序设计竞赛同步赛(低年级)
    ACM_X章求和(数学)
    goj 扫雷(dfs)
    Sereja and Brackets(括号匹配)
    NOIP模拟赛 迷路
    NOIP模拟赛three(3)
    NOIP模拟赛2(two)
    NOIP模拟赛1(one)
    czy的后宫5
    [BZOJ3436]小K的农场
  • 原文地址:https://www.cnblogs.com/csgc0131123/p/5290453.html
Copyright © 2011-2022 走看看