Under construction

Still being built. Things may change

Cookie Farms

Interview

Time limit5sMemory limit512 MB

Summary
Decide how many cookie farms to buy before waiting so the time to hold X cookies is as short as possible.
Level

Medium4 of 10

Topics
Greedy, Math
Solved
No attempts yet

Problem

You start with 0 cookies and earn 2 cookies per second by clicking a giant cookie. Whenever you hold at least CC cookies, you can buy a cookie farm. Each farm costs CC cookies and adds FF cookies per second to your production.

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

Cookies accumulate continuously. 0.1 seconds after the start you have 0.2 cookies, and π\pi seconds after the start you have 2π2\pi cookies.

For C=500.0C=500.0, F=4.0F=4.0, X=2000.0X=2000.0 the best strategy plays out like this.

  1. You start with 0 cookies and a production of 2 cookies per second.
  2. After 250 seconds you hold C=500C=500 cookies and buy a farm that produces F=4F=4 cookies per second.
  3. After the purchase you hold 0 cookies and produce 6 cookies per second.
  4. The next farm also costs 500 cookies, which you can afford after about 83.3333333 seconds.
  5. After the second purchase you hold 0 cookies and produce 10 cookies per second.
  6. The farm after that also costs 500 cookies, which you can afford after 50 seconds.
  7. After the third purchase you hold 0 cookies and produce 14 cookies per second.
  8. A fourth farm would also cost 500 cookies, but buying it is worse than waiting. Waiting for X=2000X=2000 cookies takes about 142.8571429 seconds.

The total time is 250+83.3333333+50+142.8571429=526.1904762250 + 83.3333333 + 50 + 142.8571429 = 526.1904762 seconds.

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.

CC, FF, and XX each consist of an integer part of one or more digits, a decimal point, and a fractional part of one to five digits. The integer part has no leading zero.

  • 1≤T≤1001 \le T \le 100
  • 1≤C≤100001 \le C \le 10000
  • 1≤F≤1001 \le F \le 100
  • 1≤X≤1000001 \le X \le 100000

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.

Round yy to seven decimal places and always print seven digits after the decimal point, padding with zeros.

Hint

Whether one more farm pays off depends on your current production per second. Once buying one more farm stops paying off, every later farm is a loss as well, so buy farms only while they still pay off.

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