Under construction

Still being built. Things may change

Cookie Farms

Interview

Time limit5sMemory limit512 MB

Summary
Starting at 2 cookies per second, decide how many farms that cost C and add F each to buy before waiting until X cookies are held.
Level

Medium5 of 10

Topics
Greedy, Math
Solved
No attempts yet

Problem

You start with 0 cookies. Clicking a giant cookie earns you 2 cookies per second. Whenever you hold at least CC cookies, you may buy a cookie farm. Each farm costs CC cookies and raises your production by FF cookies per second.

You win the moment you hold XX cookies that you have not spent on farms. Compute how long winning takes if you play the best possible strategy.

Cookies accumulate continuously. After 0.1 seconds you have 0.2 cookies, and after π\pi seconds you have 2π2\pi cookies. Buying a farm takes no time, and you may buy any number of farms.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains three space-separated real numbers CC, FF and XX, with the meanings given above.

Each of CC, FF and XX is written as at least one digit, then a decimal point, then one to five digits. No number has a leading zero.

  • 1≤T≤1001 \le T \le 100
  • 1≤C≤5001 \le C \le 500
  • 1≤F≤41 \le F \le 4
  • 1≤X≤20001 \le X \le 2000

Output

For each test case print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is the minimum number of seconds needed to hold XX cookies.

Print yy rounded to exactly seven decimal places, keeping trailing zeros. The judge compares the output string exactly. Every answer in the input data sits far from a rounding boundary, so double precision arithmetic produces the same digits.

Hint

Whether one more farm pays off depends only on your current production rate. As the rate grows, the time needed to earn a farm shrinks slowly, while the time the farm saves shrinks faster. Once buying stops paying off, it never pays off again.

Examples1

  1. Example 1

    Input
    4
    30.0 1.0 2.0
    30.0 2.0 100.0
    30.50000 3.14159 1999.19990
    500.0 4.0 2000.0
    
    Expected output
    Case #1: 1.0000000
    Case #2: 39.1666667
    Case #3: 63.9680013
    Case #4: 526.1904762