社区讨论

P3912素数个数求助

学术版参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lwd2jn1r
此快照首次捕获于
2024/05/19 13:00
2 年前
此快照最后确认于
2024/05/19 15:15
2 年前
查看原帖
我用欧式筛写素数个数这道题,最后一个点mlemle,在线等,悬关
代码
CPP
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e8;
bool vis[N];
int prime[10000005],cnt;
void init(int x){
    for(int i=2;i<=x;i++){
        if(vis[i]==true){
            continue;
        }
        for(int j=i*i;j<=x;j=j+i){
            vis[j]=true;
        }
    }
    for(int i=2;i<=x;i++){
        if(vis[i]==false){
            cnt++;
            prime[cnt]=i;
        }
    }
}
signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    int n;
    // cin>>n;
    scanf("%lld",&n);
    init(n);
    printf("%lld",cnt);
    // cout<<cnt;
    return 0;
}
也不知道是用
CPP
scanf("%lld",&n);
printf("%lld",cnt);
还是
CPP
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
这样快
或者是有其他什么原因,求助!!!

回复

2 条回复,欢迎继续交流。

正在加载回复...