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

H2O题!

Posted by KatrineYang at 2016-08-21 10:03:09 on Problem 1844
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
	int m;
	scanf("%d", &m);
	double n_ = (-1+sqrt(1.0+8*m))/2;
	int n = (int) n_;
	if(abs(n_-n) > 1e-6) n++;
	for(int nn = n; ; nn++){
		if((nn*(nn+1)/2-m)%2 == 0){
			printf("%d\n", nn);
			break;
		}
	}
	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