Description
Input
Output
Sample Input
10 6 7 11 15 16 100 10000 1000 21 22 0
Sample Output
10 30 6 14 7 18 11 35 15 55 16 61 100 945 10000 942820 1000 29820 21 91 22 98
#include<iostream>
#include<cmath>
using namespace std;
int main( )
{
int n;
int a,b,s,k;
while(cin>>n&&n)
{
s=0;
k=(-1+sqrt(1+8*n))/2;
for(a=1;a<=k;a++)
s=s+a*a;
s=s+(n-k*(k+1)/2)*a;
cout<<n<<‘ ‘<<s<<endl;
}
return 0;
} 原文:https://www.cnblogs.com/mqxnongmin/p/10949396.html