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:80水过~~~赤果果的水题In Reply To:80水过~~~赤果果的水题 Posted by:ckl at 2010-02-16 00:28:43 #include<iostream> #include<math.h> using namespace std; int f(int t) { if(t==1) return 1; else return t*t+f(t-1); } //求解1*1+2*2+...+t*t int main() { int x; while(scanf("%d",&x)&&x!=0){ int n=sqrt(double(x*2)); int m=n*(n+1)/2-x; if(m>0)printf("%d %d\n",x,f(n-1)+(n-m)*n); else { if(m<0)printf("%d %d\n",x,f(n)-m*(n+1)); else printf("%d %d\n",x,f(n)); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator