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

靠 如此简单一题 高精度都不要!!!

Posted by ecjtuFFF at 2009-02-18 14:23:58 on Problem 2000
#include<stdio.h>
int fun2(int n)
{
	return n*(n+1)/2;
}
int fun(int m)
{
	int n,i;
	for(i=1;i<=m;i++)           //控制 m 范围
	{
		if(m>=fun2(i)&&m<fun2(i+1))
		{
			n=i;break;
		}
	}
	return n;
}
__int64 fun3(int m,int n)
{
	return n*(n+1)*(2*n+1)/6+(m-n*(n+1)/2)*(n+1);
	//return n*(m-n/3-(n*n/6));
}
int main()
{
	int m;
	while(scanf("%d",&m)!=EOF)
	{
		if(m==0)break;
		printf("%d %I64d\n",m,fun3(m,fun(m)));
	}
	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