Cruel Math Teacher, II
Time limit1sMemory limit128 MB
Find a real root of an odd-degree polynomial with one real root in [-1e6, 1e6], accurate to 5e-5, and print the root times 1000 truncated toward zero.
- Level
Medium5 of 10
- Topics
- Binary search, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
As if raising numbers to powers were not cruel enough, Bessie's cruel math teacher has invented an even crueler assignment: find a root (a zero) of a polynomial.
Every such polynomial has an odd highest degree () and has exactly one real solution in the range ; at that solution the polynomial evaluates to a value that is very close to (or exactly) in floating-point arithmetic.
Given a polynomial with real coefficients (), find a value of that lies within of the true root. Multiply that value of by and print it as a truncated (non-rounded) integer, discarding the fractional part toward zero.
For example, consider the cubic . Its solution satisfies , so ; the correct output is therefore .
The polynomial is , where means raised to the -th power.
No answer requires more than six significant digits, and every answer is small enough that it can be incremented by in double-precision floating point without a serious loss of precision.
Hint: choose each new guess for so that the search interval shrinks at every step.
Input
- Line 1: a single integer .
- Lines 2 to : line contains a single real number (for ).
Output
- Line 1: a single integer — the value of closest to the root, multiplied by and truncated toward zero.