20分,案例全过,求调
  • 板块灌水区
  • 楼主A_Spring114514
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/10/18 18:49
  • 上次更新2024/10/18 21:05:44
查看原帖
20分,案例全过,求调
1341125
A_Spring114514楼主2024/10/18 18:49
#include<bits/stdc++.h>
using namespace std;
bool isprime(int a){
	if(a==2) return 1;
	for(int i=1;i*i<=a;i++){
		if(a%i==0) if(i!=1) return 0;
	}
	return 1;
}
int main(){
	int l,tot=0,i=2,n;
	cin>>l;
	if(l<2) {
		printf("0\n");
		return 0;
	} else if(l==2) {
		printf("2\n1\n");
		return 0;
	}
	while(true){
		if(tot>=l) break;
		if(isprime(i)){
			if(tot+i<=l){
				tot+=i;
				++n;
				cout<<i<<endl;
			}
			else break;
		}
		++i;
	}
	cout<<n<<endl;
	return 0;
}


2024/10/18 18:49
加载中...