20分求助
查看原帖
20分求助
1444395
McdullWang楼主2024/12/25 21:06
#include <bits/stdc++.h>
using namespace std;
int main(){
    int l,flag=0,i=2,total=0,t=0;
    cin>>l;
    while(total<=l){
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
               flag++; 
            }
        }
        if(flag==0){
            cout<<i<<endl;
            total+=i;
            t++;
        }
        if(total>l){
        	break;
		}
        flag=0; 
        i++;
	}
	cout<<t-1;
    return 0;
}
2024/12/25 21:06
加载中...