Infinity Area
InterviewTime limit20sMemory limit1024 MB
Given R, A, B, sum the areas of circles whose radii alternate between multiplying by A and integer-dividing by B, until a radius reaches zero.
- Level
Easy3 of 10
- Topics
- Simulation, Math
- Solved
- No attempts yet
Problem
Let us assume for the simplicity of this problem that the Infinity symbol is made of circles which touch externally at point as shown below, and let us call it the center of the infinity.

You are given three integers , , . You are currently at the center of the infinity. You first draw the right circle with radius and return to the center of the infinity. After that, you draw the left circle with radius equal to the radius of the last circle multiplied by . After reaching the center, you draw the right circle with radius equal to the radius of the last circle divided by (integer division). After reaching the center again, you draw the left circle with radius equal to the radius of the last circle multiplied by .
You keep drawing the left and right circles in this alternating order until the radius of the circle to be drawn becomes zero. Calculate the sum of areas of all the circles drawn. It is guaranteed that the process terminates after a finite number of steps.
Input
The first line of the input gives the number of test cases, . Each of the next lines contains three integers , , and , where is the radius of the first circle, and and are the parameters used to compute the radii of the subsequent circles.
Output
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the sum of areas of all the circles drawn until the radius of the circle to be drawn becomes zero.
is considered correct if it is within an absolute or relative error of of the correct answer.