40pts
查看原帖
40pts
942118
Minecraft_Sep楼主2023/11/1 16:27
#include<iostream>
using namespace std;
int main()
{
	int L,s=0,gs=0;
	cin>>L;
	if(L==2)
	{
		cout<<2<<endl;
		gs++;
		s+=2;
	}
	else
	{
	
		for(int i=2;i<L;i++)
		{
			bool bz=true;
			for(int j=2;j<i;j++)
			{
				if(i%j==0)
				{
					bz=false;
					break;
				}
			}
			if(bz==true)
			{
				cout<<i<<endl;
				s+=i;
				gs++; 
				if(s>=L)
				{
					break;
				}
			}
		}
	}
	cout<<gs<<endl;	
}
2023/11/1 16:27
加载中...