40pts求助
查看原帖
40pts求助
1234287
BH5970楼主2024/11/29 21:44
#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;
}

为什么不行?

2024/11/29 21:44
加载中...