This page is still under construction.

Parts of this page are still being built. What you see may change.

Spirograph

Time limit8sMemory limit512 MB

Summary
For each test case, compute the total arc length of a hypotrochoid traced by a pinhole in a circle of radius Q rolling inside a fixed circle of radius P, with pinhole offset R.
Level

Hard8 of 10

Topics
Math, Geometry, Simulation
Solved
No attempts yet

Problem

Some of you may have seen an instrument like the one in the figure below.

Figure 1: Spirograph

There is a fixed circle (labeled A in the figure) and a smaller interior circle with several pinholes (labeled B). Put a pen tip through one of the pinholes, then roll circle B without slipping around the inside of circle A, and you can draw curves like the one below. Such curves are called hypotrochoids.

Figure 2: An example hypotrochoid

Given the radius of the fixed circle A, the radius of the interior circle B, and the distance between the center of B and the pinhole used, write a program that computes the length of the hypotrochoid.

Input

The input consists of multiple test cases. Each test case is described by a single line containing three integers P, Q, R in that order, where P is the radius of the fixed circle A, Q is the radius of the interior circle B, and R is the distance between the center of circle B and the pinhole. You can assume that 0 ≤ R < Q < P ≤ 1000. P, Q, and R are separated by a single space, and no other spaces appear in the input.

The end of input is indicated by a line with P = Q = R = 0.

Output

For each test case, output the length of the hypotrochoid curve. The error must be within 10-2 (= 0.01).

Examples1

  1. Example 1

    Input
    3 2 1
    3 2 0
    0 0 0
    
    Expected output
    13.36
    6.28