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:我的

Posted by first at 2005-12-31 14:42:00 on Problem 1844
In Reply To:超简单,思路很清晰的解法 Posted by:zsl2007 at 2005-12-31 13:47:35
#include <iostream>
#include <cmath>
using namespace std;
void main()
{
	int n;
	while(cin>>n)
	{
		int ans = (-1 + sqrt(1 + 8*n))/2;
		ans = ( n > ans*(ans+1)/2 ) ? ans + 1 : ans;
		for(int i = ans; (i*(i+1)/2 - n)%2 ; i ++);
		cout << i <<endl;
	}
}

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