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 |
我的AC代码#include<stdio.h> int total(int x); main() { int a,i,j,k,m; long b,sum; while(scanf("%d",&a)!=EOF&&a!=0) { sum=b=0; for(i=1;;i++) { sum+=i; if(sum>=a) { k=i-1; break; } } m=a-total(k); for(j=1;j<=i-1;j++) { b+=j*j; } b+=i*m; printf("%d %d\n",a,b); } } int total(int x) { int i,sum=0; for(i=1;i<=x;i++) { sum+=i; } return sum; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator