Roots Intervals

Interview

Time limit1sMemory limit128 MB

Summary
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 f(x)=1−x2f(x) = 1 - x^2 defined on an interval [a,b][a, b], together with nb≥1nb \ge 1 subintervals [xi,xi+1][x_i, x_{i+1}] for i=1,…,nbi = 1, \dots, nb, where x1=ax_1 = a, xnb+1=bx_{nb+1} = b, and the nbnb subintervals divide [a,b][a, b] into equal parts. Count how many of these subintervals contain an "observable" root of f(x)f(x).

A root inside a subinterval [xi,xi+1][x_i, x_{i+1}] is called observable if its existence can be decided without inspecting the behaviour of f(x)f(x) for xi<x<xi+1x_i < x < x_{i+1}: each subinterval is a black box, and you may only read the values of ff at its two endpoints. Concretely, a subinterval contains an observable root exactly when f(xi)f(x_i) and f(xi+1)f(x_{i+1}) have opposite signs (by continuity a root must then lie between them), or when one of the endpoints is itself a root (f(xi)=0f(x_i) = 0 or f(xi+1)=0f(x_{i+1}) = 0). 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 [a,b][a, b] of f(x)f(x) and gives the two real numbers aa and bb followed by the integer nbnb, 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 f(x)f(x).

Examples1

  1. Example 1

    Input
    -2 2 2
    0 100 5
    -1 1 1
    
    Expected output
    2
    1
    1