只A了2个点,求助!!
查看原帖
只A了2个点,求助!!
206430
_tyc楼主2020/9/26 18:44
#include <iostream>
using namespace std;
bool prime(int a) {
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
		  return false;
	}
	return true;
}
int main() {
	int l, ans = 2, cnt = 1, shu = 3;
	cin >> l;
	if (l == 1)  {
		cout << "0";	
	}
	else if (l < 5) {
		cout << ans << endl << cnt;
		return 0;
	} else {
		cout << "2" << endl;
		while (ans < l) {
			if (prime(shu)) {
				cout << shu << endl;
				ans += shu;
				cnt++;
			}
			shu += 2;
		}
		cout << cnt;
	}
	return 0;
}
2020/9/26 18:44
加载中...