Files
python/TangDou/LuoGuBook/P5723_AyeSieve.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
613 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
//埃拉筛
int primes[N], cnt;
bool st[N];
void get_primes(int n) {
for (int i = 2; i <= n; i++)
if (!st[i]) {
primes[cnt++] = i;
for (int j = 2 * i; j <= n; j += i) st[j] = true;
}
}
int L, ans, sum;
int main() {
cin >> L;
//预处理 提前准备出来
get_primes(L);
for (int i = 0; i < cnt; i++) {
ans += primes[i];
if (ans > L) break;
printf("%d\n", primes[i]);
sum++;
}
printf("%d\n", sum);
return 0;
}