Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:80水过~~~赤果果的水题

Posted by qylsw at 2010-07-17 14:26:15 on Problem 2000
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator