Von Neumann and the Fly

Given train speed S, fly speed T, and initial gap D, compute how far the fly travels before the two trains collide.

Easy2MathImplementationSimulationBrute forceInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

The following story is told about von Neumann, one of the greatest geniuses in history.

One day a colleague tried to test von Neumann's genius with this question.

"Two trains stand at opposite ends of a 200 mile track and start toward each other at 50 miles per hour. From the moment they start until they collide, a fly flies back and forth between the two trains at 75 miles per hour. How many miles does the fly travel in total?"

Von Neumann heard the question and answered 150 miles without a second of delay. His colleague was very disappointed and said:

"You are clever, just as they say. Most people try to solve this with an infinite series, which takes a very long time. With one simple piece of reasoning you get the fly's distance at once. You used that reasoning, didn't you?"

Von Neumann answered:

"No, I summed the infinite series."

Here is the infinite series solution. Put trains A and B on a number line. Call the train that starts next to the fly A and take its position as the origin, so train B sits 200 miles from the origin. At time tt the fly is at 75t75t and train B is at 20050t200 - 50t, so the fly first meets train B 120 miles from the origin. Those 120 miles are the fly's first leg a1a_1. At that moment train A is 80 miles from the origin, because train A moves at 2/32/3 of the fly's speed. The gap between the trains has shrunk to 40 miles, so by the same argument the fly's second leg a2a_2 is (1/5)a1(1/5)a_1. Continuing this way, ai+1=(1/5)ia1a_{i+1} = (1/5)^i a_1, and the fly's total distance is i0(1/5)ia1=150\sum_{i \ge 0} (1/5)^i a_1 = 150, that is, 150 miles.

The simple reasoning the colleague had in mind is this. The trains meet after 200/(50×2)=2200 / (50 \times 2) = 2 hours. The fly moves at 75 miles per hour for those 2 hours, so it covers 2×75=1502 \times 75 = 150 miles.

Now write a program that solves the problem. Our computer is slower than von Neumann's brain, so it cannot build the answer from an infinite series. Use the simple reasoning instead: given the train speed SS, the fly speed TT, and the initial distance DD between the two trains, compute the distance FF the fly travels until the trains meet. Both trains move at the same speed, and the fly never stops before the collision.

Input

The first line contains the train speed SS, the fly speed TT, and the initial distance DD between the two trains, separated by spaces. All three values are positive integers no greater than 10,000, T>ST > S, and DD is a multiple of 2S2S.

Output

Print the distance FF the fly travels. Because DD is a multiple of 2S2S, FF is always an integer.