https://www.luogu.com.cn/problem/P5723
不是难题,但是倘若忽略L<2的情况就无法AC,Lougu得分只有80。因此写完题后一定要把各种边界性质的数据想出并用于测试
Code
`#include
include
include
include
include
include
include
using namespace std;
int p(int a)
{
if(a1)return 0;if(a2)return 1;
for(int i=2;i<a;i++)
if(a%i==0)return 0;
return 1;
}
int main()
{
int L,ans=0,no=0;
cin>>L;
if(L<2)cout<<0;
for(int i=2;i<=L;i++)
{
if(p(i)==1)
{
ans+=i;
if(ans>L)
{
cout<<no;
return 0;
}
cout<<i<<endl;
no++;
}
}
return 0;
}
`