20分,质数筛有合数遗漏,求大佬指正错误

P5736 【深基7.例2】质数筛

@[Glooda](/user/746267) 18-19行删去 13行改为 ```cpp return 1; ``` 函数部分 ```cpp int sushu(int x){ if(x==2){ return 1; } if(x==1){ return 0; } else for(int i=2;i<=x;i++){ if(i==x){ return 1; } if(x%i==0){ return 0; } } } ```
by gugusbx @ 2023-05-19 21:03:50


@[gugusbx](/user/525549) 感谢神犇大师!!!AC了!!!
by Glooda @ 2023-05-19 21:06:48


``` #include<bits/stdc++.h> using namespace std; int No(int s) { if (s < 2) { return 0; } for (int x = 2; x * x <= s; x++) { if (s % x == 0) { return 0; } } return 1; } int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (No(a[i])) { cout << a[i] << " "; } } return 0; } ```
by jiangjinke @ 2023-06-15 15:07:56


|