Roots Intervals
InterviewTime limit1sMemory limit128 MB
Given interval [a,b] split into nb equal subintervals, count subintervals where f(x)=1-x^2 has a sign change or zero at endpoints.
- Level
Easy3 of 10
- Topics
- Implementation, Simulation, Math
- Solved
- No attempts yet
Problem
Consider the function defined on an interval , together with subintervals for , where , , and the subintervals divide into equal parts. Count how many of these subintervals contain an "observable" root of .
A root inside a subinterval is called observable if its existence can be decided without inspecting the behaviour of for : each subinterval is a black box, and you may only read the values of at its two endpoints. Concretely, a subinterval contains an observable root exactly when and have opposite signs (by continuity a root must then lie between them), or when one of the endpoints is itself a root ( or ). If both endpoints share the same nonzero sign, no root can be guaranteed, even though the subinterval might still contain an even number of roots.
Input
The input consists of several data sets and is read until end of file. Each data set describes one interval of and gives the two real numbers and followed by the integer , the number of subintervals. White space may appear freely between the numbers. The input is guaranteed to be correct.
Output
For each data set, print a single integer on its own line, starting at the beginning of the line: the number of subintervals that contain an observable root of .