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; int main () { int k,i,sum=0,sum1=0; while (scanf("%d",&k)!=EOF&&(k!=0)) { sum=0; sum1=0; if (k==1) {cout<<k<<' '<<"1"<<endl;continue;} if (k==2) {cout<<k<<' '<<"3"<<endl;continue;} if (k==3) {cout<<k<<' '<<"5"<<endl;continue;} for (i=1;i<=k;i++) { sum=sum+i; if (sum<=k) { sum1=sum1+i*i; continue; }else break; } sum1=sum1+(k-(sum-i))*i; cout<<k<<' '<<sum1<<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