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

我的AC代码

Posted by 244549721 at 2011-07-27 13:07:49 on Problem 2000
#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:
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