You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
613 B

#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;
}