lipengfu @ 2023-03-22 21:31:57
#include <bits/stdc++.h>
using namespace std;
int main(){
long long k,z=0,l;
cin >> k;
for(long long i=1;i<=k;i++)
k-=i,z+=i*i,l=i;
z+=k*l;
cout<< z;
return 0;
}
by dk_qwq @ 2023-03-22 21:39:50
最后的z+=k*l;
应为z+=k*(l+1);
by Yinsh @ 2023-03-22 21:44:18
@lipengfu 你的最后一行
z+=k*l
是将答案加上最后不完整的
by lipengfu @ 2023-03-22 22:21:01
谢谢大佬们
by lipengfu @ 2023-03-22 22:24:02
实验成功了,欧耶!!!
by JIAOBO226016 @ 2023-08-03 23:17:40
#include <bits/stdc++.h>
using namespace std;
int main(){
long long k,z=0,l;
cin >> k;
for(long long i=1;i<=k;i++)
k-=i,z+=i*i,l=i;
z+=k*(l+1);
cout<< z;
return 0;
}
by JIAOBO226016 @ 2023-08-03 23:18:30
@JIAOBO226016 这个就是修改后的代码