#include<bits/stdc++.h>
using namespace std;
bool a[100005];
void isprime (int s) {
for (int i = 2; i*i <= s; i++) {
if (a[i] == 0) {
for (int j = i*i; j <= s; j += i) {
a[j] = 1;
}
}
}
return;
}
int main () {
int n;
cin >> n;
isprime(n);
int cnt = 0;
int sum = 0;
for (int i = 2; i <= n; i++) {
if (a[i] == 0) {
cnt++;
sum += i;
cout << i << endl;
}
if (sum >= n) {
break;
}
}
cout << cnt << endl;
return 0;
}
为什么不行?