Paint Mix
Time limit1sMemory limit128 MB
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 gallons of black paint. The other (the white pail) contains gallons of white paint. You perform a number of iterations of pouring paint. In each iteration you first pour cups of paint from the black pail into the white pail (and thoroughly mix the white pail), then pour cups of paint from the white pail back into the black pail (and thoroughly mix the black pail). , , and are positive integers; each of and is at most , and (recall that 1 gallon equals 16 cups). The white pail's capacity is at least .
As you perform many successive iterations, the ratio of black paint to white paint in each pail approaches . Although these ratios never become exactly , one can ask: how many iterations are needed so that the black-to-white paint ratio in each of the two pails differs from by less than a given tolerance. The tolerance is defined to be .
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 , , and as described above. The input is terminated by a line where , 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 by less than the tolerance.