埃氏筛#8W,#10T,救救蒟蒻吧qwq
查看原帖
埃氏筛#8W,#10T,救救蒟蒻吧qwq
260092
qzhwmjb楼主2020/9/17 20:17
#include<bits/stdc++.h>
using namespace std;
bool v[100000005];
int tot;
int main(){
	//freopen("count.in","r",stdin);
	//freopen("count.ans","w",stdout);
	int n;
	int i,j,k;
	cin>>n;
	memset(v,true,sizeof(v));
	for (i=2;i<n;i++){
		if (v[i]==true){
			tot++;
			for (j=i+i;j<n;j+=i){
				v[j] = false; 
			}
		}
		
	}	
	cout<<tot<<endl;
	return 0;
}

#8数据
输入

4974953

输出

346862

2020/9/17 20:17
加载中...