#C06L01P04. C06.L01.筛选法求质数.填空题4.质数个数(筛选法优化)
C06.L01.筛选法求质数.填空题4.质数个数(筛选法优化)
题目描述
输入 ,输出 以内的质数的个数。()
输入格式
一个整数 。
输出格式
一个整数,代表 以内的质数的个数。
样例
10
4
程序填空
#include<bits/stdc++.h>
using namespace std;
bool flag[1001];
int main()
{
int n,cnt=0;
cin>>n;
for(int i=2;i<= 填空(1) ;i++){
if( 填空(2) ) //说明这是一个素数
{
cnt++;
for(int j=2;i*j<=n;j++)
flag[i*j] = true;
}
}
cout<<cnt;
return 0;
}
填空(1): {{ input(1) }}
填空(2): {{ input(2) }}
相关
在以下作业中: