Files
python/GESP/Level5/Eratosthenes/1.cpp
HuangHai a6ed9954d6 'commit'
2025-09-24 15:40:59 +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 i = 1; i <= n; i++)
if (b[i])
cout << i << " ";
return 0;
}