#include <bits/stdc++.h> #define endl "\n" using namespace std; int n,c=0; bool r[50000001]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freeopen(".in","r",stdin); //freeopen(".out","w",stdout); cin>>n; for(int i=2;ii<=n;i++){ if(!r[i]){ for(int j=ii;j<=n;j+=i)r[j]=true; } } for(int i=2;i<=n;i++)if(!r[i])c++; cout<<c; return 0; }
共 1 条回复
#include <bits/stdc++.h> #define endl "\n" using namespace std; int n,c=0; bool r[50000001]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //freeopen(".in","r",stdin); //freeopen(".out","w",stdout); cin>>n; for(int i=2;ii<=n;i++){ if(!r[i]){ for(int j=ii;j<=n;j+=i)r[j]=true; } } for(int i=2;i<=n;i++)if(!r[i])c++; cout<<c; return 0; }