大佬们!求助!这道题我为什么会全错?/(ㄒoㄒ)/~~

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

望丰展使md
by diqiuyi @ 2023-07-17 10:22:11


@[wenchuang](/user/1034912) 你这质数筛错了罢,为什么有一个 j 不是 a[i] 的因数就判定为质数啊
by diqiuyi @ 2023-07-17 10:23:50


谢谢大佬
by wenchuang @ 2023-07-17 11:17:50


```cpp #include <iostream> using namespace std; int n,a[100005] = {1,1},q; void f(int q){ for(int i = 2;i <= q;i++){ if(a[i] == 1){ continue; } for(int j = i * 2;j <= q;j += i){ a[j] = true; } } } int main(){ cin >> n; f(100001); for(int i = 1;i <= n;++i){ cin >> q; if(!a[q] == 1){ cout << q << " "; } } return 0; } ```
by lucas_777 @ 2023-07-21 20:55:41


|