0027. Iteration

Имя входного файла: iterate.in
Имя выходного файла: iterate.out
Ограничение по времени: 2 s
Ограничение по памяти: 64 megabytes

Misha has written a program that solves a difficult problem using iterative method. Now he wants to estimate the number of iterations.

His method uses a sequence zi as its part. This sequence is constructed according the following rules. The first number in sequence is a given real number z0. The subsequent numbers are calculated using formula . The method stops if the value of zi is negative. It is guaranteed there will be neither division by zero nor zero-valued zi before termination condition.

Write a program that evaluates the number of the first negative member of this sequence.

Input file

Input file consists of three numbers: A, B (|A|, |B| ≤ 108) and z0. z0 is a real number with no more than 9 digits after decimal point. Also z0 will not have more than 9 significant digits or exceed 106 by its absolute value. A and B are integer numbers.

Output file

Write only one integer number n – the minimal n satisfying condition zn<0. If all numbers in the sequence will be positive, display -1.

Examples:

iterate.initerate.out
1 1 2 1


Источник: Petrozavodsk training camp, Summer 2002. Startup contest
Автор: Andrew Lopatin, Nick Durov

Обсудить       Отправить решение



Версия для печати