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 8ab12097207 at 2009-07-16 11:18:44 on Problem 2000
In Reply To:公式很容易推导啊 Posted by:peterdi at 2008-12-09 14:14:35
> // 公式
> //       1 2 3 4 5 6 7 8 9 10...
> //      1 2 2 3 3 3 4 4 4 4...
> // 对任意的day coinnum=1*1+2*2+3*3+...
> // 所以得到day=n*(n+1)/2
> // 由day求出n 判断n*(n+1)/2与day的关系	 
> // 若相等则 coinnum=1*1+2*2+3*3+..+n*n=n*(n+1)*(2*n+1)/6//这里因该为6
> // 若不等则 coinnum+=(day-n*(n+1)/2)*(n+1)//应该加括号的。
> // o(1)
代码如下:
#include <stdio.h>
int main(int argc, char* argv[])
{
	int day,sum,k;
	while(scanf("%d",&day)&&day!=0)
	{
		sum=0;
		k=1;
		while((k+2)*(k+1)/2<day)
			k++;
		sum=k*(k+1)*(2*k+1)/6;
		sum+=(day-k*(k+1)/2)*(k+1);
		printf("%d %d\n",day,sum);
	}
	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