Paint Mix

Time limit1sMemory limit128 MB

Summary
For each test case, find how many mix iterations make the black-to-white ratio in both pails within 0.00001 of B/W.
Level

Medium4 of 10

Topics
Simulation, Math
Solved
No attempts yet

Problem

You are given two large pails. One of them (the black pail) contains BB gallons of black paint. The other (the white pail) contains WW gallons of white paint. You perform a number of iterations of pouring paint. In each iteration you first pour CC cups of paint from the black pail into the white pail (and thoroughly mix the white pail), then pour CC cups of paint from the white pail back into the black pail (and thoroughly mix the black pail). BB, WW, and CC are positive integers; each of BB and WW is at most 5050, and C<16⋅BC < 16 \cdot B (recall that 1 gallon equals 16 cups). The white pail's capacity is at least B+WB+W.

As you perform many successive iterations, the ratio of black paint to white paint in each pail approaches B/WB/W. Although these ratios never become exactly B/WB/W, one can ask: how many iterations are needed so that the black-to-white paint ratio in each of the two pails differs from B/WB/W by less than a given tolerance. The tolerance is defined to be 0.000010.00001.

Input

The input consists of several lines. Each line contains the input for one instance of the problem: three positive integers giving the values of BB, WW, and CC as described above. The input is terminated by a line where B=W=C=0B = W = C = 0, which is not processed.

Output

Print one line of output for each instance. Each line contains a single positive integer: the smallest number of iterations required so that the black-to-white paint ratio in each of the two pails differs from B/WB/W by less than the tolerance.

Examples1

  1. Example 1

    Input
    2 1 1
    2 1 4
    3 20 7
    0 0 0
    
    Expected output
    145
    38
    66