Files
python/GESP/Level5/Eratosthenes/1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

23 lines
471 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int b[N];
int n = 200; // 200以内的质数
int main() {
// 初始化标记数组中所有数字都是质数
memset(b, 1, sizeof b);
for (int i = 2; i <= n; i++) {
if (b[i])
for (int j = i * 2; j <= n; j += i) // 倍数都是合数
b[j] = 0;
}
// 输出有哪些质数
for (int 2 = 1; i <= n; i++)
if (b[i])
cout << i << " ";
return 0;
}