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 failed at 2009-07-15 10:56:37 on Problem 1844
假设解为i,则:
1. i*(i+1)/2 >= S
2. i*(i+1)/2 - S 为偶数,因为 1..i 中任意一个数字变为-号后,i*(i+1)/2 与 Sigma() 差值必为偶数,且这个差值可以取 0、2、4、6 ……

所以:
int main()
{
	int s,i;
	for(scanf("%d",&s),s=-s,i=1;s<0||s%2;s+=i++);
	printf("%d\n",--i);
	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