LBTDBS @ 2024-12-05 15:54:21
#include<bits/stdc++.h>
using namespace std;
int main(){
long long sum1=0,sum2=0,t=0;
int i,j,k;
cin>>k;
for(i=0;i<k;i++){
sum1+=i;
if(sum1<=k&&(sum1+i)>k)break;
}
for(j=0;j<=i;j++){
sum2+=j*j;
}
cout<<sum2+(k-sum1)*(i+1)<<endl;
return 0;
}
by YBa2Cu3O7 @ 2024-12-05 16:13:21
k=1情况?
by LBTDBS @ 2024-12-05 17:37:00
@YBa2Cu3O7 确实不单止是1错了,2也错了。谢了哥
by LBTDBS @ 2024-12-05 19:48:07
@LBTDBS
for(i=1;i<=k;i++){
sum1+=i;
if(sum1<=k&&(sum1+i+1)>k)break;