40分求助!
查看原帖
40分求助!
994152
dzl0620楼主2024/1/24 09:33
#include<bits/stdc++.h>
using namespace std;
int main(){
	int l;
	int i,k;
	int s=0,num=0;
	bool b=true;
	cin>>l;
	for(k=2;k<=l;k++){
		if(k==2||k==3){
			cout<<k<<endl;
			s+=k;
			num+=1;
			b=false;
		}
		if(k%2==0||k==1||k==0){
			b=false;
		}
		for(int i=3;i<sqrt(k);i+=2){
			if(k%i==0){
				b=false;
			}
		}
		if(s>l){
			break;
		}
		if(b){
			cout<<k<<endl;
			s+=k;
			num+=1;
		}
	}
	cout<<num;
	return 0;
}
2024/1/24 09:33
加载中...