Submission #3440982
Source Code Expand
#include<bits/stdc++.h> using namespace std; bool a[10000010];//合数表 int main() { long long n; scanf("%lld",&n); for(int i=2;i<=n;i++){ if(a[i])continue;//如果已经在合数表里了,相当于下面动图中有颜色的部分 for(int j=i;j<=n;j+=i){//如果不满足,就一定是质数 if(a[j])continue; a[j]=1;//将找到的这个质数的倍数全部上色,即加入合数表 } b[i]=1; } long long ans=0; for(int i=2;i<=n-1;i++){ if(b[i])ans++; }//统计即可 cout<<ans<<endl; }
Submission Info
Submission Time | |
---|---|
Task | A - 与えられた数より小さい素数の個数について |
User | luogu_bot1 |
Language | C++ (GCC 5.4.1) |
Score | 0 |
Code Size | 611 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:14:9: error: ‘b’ was not declared in this scope b[i]=1; ^ ./Main.cpp:18:12: error: ‘b’ was not declared in this scope if(b[i])ans++; ^ ./Main.cpp:7:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&n); ^