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 |
Re:100题留念,有此里程碑,将一如既往!!!^_^In Reply To:Re:100题留念,有此里程碑,将一如既往!!!^_^ Posted by:vltam1n at 2009-12-17 11:04:22 > hehehe. #include<iostream> using namespace std; int main() { double n,j; while (cin>>n&&n!=0) { double s=0,i=1,t=0; for(i=1;;i++) { if(i*(i+1)<=2*n) { if(i*(i+1)==2*n) break; } else if(i*(i+1)>2*n&&(i*(i-1)<2*n)) { double m; i--; m=i*(i+1)/2; t=n-m; break; } } if(t==0) { for(int j=1;j<=i;j++) s=s+j*j; } else if(t!=0) { for(int j=1;j<=i;j++) s=s+j*j; s=s+t*(i+1); } cout<<n<<" "<<s<<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