蒙自二中 卢建铮(听风凭引) • 2年前
using namespace std; int main() {
int sum=0;
double n;
cin>>n;
if(sqrt(1+8*n)==1.0*int(sqrt(1+8*n))) {
int k=(sqrt(1+8*n)-1)/2;
cout<<(k*(k+1)*(2*k+1))/6;
}
if(sqrt(1+8*n)!=1.0*int(sqrt(1+8*n))) {
int k=(sqrt(1+8*n)-1)/2;
sum+=(k*(k+1)*(2*k+1))/6;
sum+=(n-(k*(k+1)/2))*(k+1);
cout<<sum;
}
return 0;
}
评论:
请先登录,才能进行评论