zoukankan      html  css  js  c++  java
  • codevs 5790 素数序数

    5790 素数序数(筛素数版)

     

    时间限制: 1 s
    空间限制: 32000 KB
    题目等级 : 黄金 Gold
     
     
     
    题目描述 Description

    给定一个整数n,保证n为正整数且在int范围内,输出n是第几个质数

    建议使用筛素数法

    输入描述 Input Description

    一行,一个整数

    输出描述 Output Description

    一行,一个整数

    样例输入 Sample Input

    3

    样例输出 Sample Output

    2

    数据范围及提示 Data Size & Hint

    int就够了。。。

    然后看限制和题目名称,你懂得

    别的没啥了吧

     1 #include<iostream>
     2 #include<cmath>
     3 using namespace std;
     4 #define maxn 20000000
     5 bool f[maxn];
     6 int main() 
     7 {
     8     int n,ans=0;
     9     cin>>n;
    10     for(int i=2;i<=n;i++) 
    11     {
    12         if(!f[i])
    13         {
    14             ans++;
    15             for(int j=1;i*j<=20000000;j++)
    16             f[i*j]=true;
    17         }
    18     }
    19     cout<<ans;
    20 }
  • 相关阅读:
    关于input()
    HDU 3746
    HDU 4335 Contest 4
    HDU 4418 高斯消元法求概率DP
    HDU 4339 Contest 4
    HDU 4334 Contest 4
    HDU 4333 Contest 4
    HDU 4332 Contest 4
    HDU 4035
    HDU 4336
  • 原文地址:https://www.cnblogs.com/sssy/p/6740917.html
Copyright © 2011-2022 走看看