applesandwich @ 2025-01-11 11:18:49
这代码一言难尽,大佬们自己看吧
样例2没过
捞
#include <bits/stdc++.h>
using namespace std;
long long a,b,k,i,days,sum;
int main()
{
cin>>k;
days=k;
for(i=0;i<=k;i++)
{
if(days>=i)
{
sum=sum+i*i;
days=days-i;
//cout<<sum<<" "<<days<<" "<<i<<endl;
}
}
if(days>0)
{
//cout<<i<<endl;
sum=sum+(i+1)*days;
cout<<sum<<endl;
//cout<<sum<<" "<<days<<endl;
}
else
cout<<sum<<endl;
return 0;
}
回复题解更好
by bsdsdb @ 2025-01-11 11:22:25
题解更好
by bsdsdb @ 2025-01-11 11:24:08
@applesandwich 出第一个循环的时候你的 i 是 k+1
by user121_2023wbm @ 2025-01-11 11:27:57
#include <bits/stdc++.h>
using namespace std;
long long a,b,k,i,days,sum;
int main()
{
cin>>k;
days=k;
for(i=0;i<=k;i++)
{
if(days>=i)
{
sum=sum+i*i;
days=days-i;
//cout<<sum<<" "<<days<<" "<<i<<endl;
}
else
break;
}
if(days>0)
{
//cout<<i<<endl;
sum=sum+(i+1)*days;
cout<<sum<<endl;
//cout<<sum<<" "<<days<<endl;
}
else
cout<<sum<<endl;
return 0;
}
by applesandwich @ 2025-01-11 11:32:58
@user121_2023wbm
by applesandwich @ 2025-01-11 11:33:50
@user121_2023wbm
40分代码?