Saturday, June 27, 2009

62. Very simple One

Problem  Diagonals
---------------------

Given that an n-gon has at least N diagonals, what is the minimum
possible value of n?

Input
-----

Input consists of multiple lines, one line per case. Each line contains
a positive integer N ( N < 1015) that indicates the minimum possible
number of diagonals. Input is terminated by a line containing a zero.
This line should not be processed.

Output
------

For each line of input produce one line of output containing the minimum
possible value for n (Number of sides).

Sample Input
------------

10
100
1000
0

Output for Sample Input
-----------------------

7
16
47

1 comments:

Anurag said...

this is formula based:
#include iostream.h
#include math.h


main() {
double N;
cin >> N;
while (N != 0) {
cout << int(ceil((3+sqrt(9+8*N))/2)) << "\n";
cin >> N;
}
}

Post a Comment