Dear123 @ 2024-01-13 20:29:57
#include <iostream>
using namespace std;
int main(){
int k,s=0,n=0;
cin>>k;
for(int i=1;i<=k;){
n++;
s=s+n*n;
i=i+n;
}
cout<<s;
}
by lij123 @ 2024-01-13 20:47:14
改成这样
#include <iostream>
using namespace std;
int main(){
int k,s=0,n=1;
cin>>k;
for(int i=1;i<=k;i++){
k-=i;
s=s+n*n;
n++;
}
cout<<s+k*n;
}
}
by lij123 @ 2024-01-13 20:47:25
@Dear123