Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
看一下哦#include<iostream> using namespace std; #include<math.h> int main(){ int i,j,n,sum; int sum1=0;int k=0; int a[50],b[50]; for(;;) { cin>>n; if(n==0) break; sum=0; for(i=1;i<n;i++) { sum=sum+i*i; if(n==(i*i+i)/2) sum1=sum; else if(n>(i*i-i)/2&&n<=(i*i+i)/2) sum1=sum-((i*i+i)/2-n)*i; } a[k]=n; b[k]=sum1; k++; } for(j=0;j<k;j++) {cout<<a[j]<<' '<<b[j]<<endl;} return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator