Under construction

Still being built. Things may change

Allergy Testing (Small)

Time limit5sMemory limit512 MB

Summary
Kelly plans pooled food tests with different waits after negative and positive results to find her single allergy trigger in the fewest worst-case days.
Level

Medium7 of 10

Topics
Dynamic programming
Solved
No attempts yet

Problem

Kelly is allergic to exactly one of NN foods, but she does not know which one. She decides to run experiments to find out.

In each experiment Kelly picks several foods and eats them all at once. AA days later she learns whether she had an allergic reaction. If there was no reaction, none of the foods she just ate is the one she is allergic to. If there was a reaction, she learns at that same moment that the food she is allergic to is among the ones she just ate, but she has to wait for the reaction to go away, so the next experiment can only start BB days after she ate. With no reaction, the next experiment starts right after those AA days.

Kelly picks the foods for each experiment based on the results of the earlier ones. She wants the worst-case number of days needed to pin down the food she is allergic to to be as small as possible. How many days is that?

Input

The first line gives the number of test cases TT. TT test cases follow. Each test case is one line holding the space-separated integers NN, AA and BB.

Limits

  • 1≤T≤2001 \le T \le 200
  • 1≤N≤10151 \le N \le 10^{15}
  • 1≤A≤B≤1001 \le A \le B \le 100

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 worst-case number of days Kelly needs to find the food she is allergic to.

Explanation

For N=4N = 4, A=5A = 5 and B=7B = 7 the answer is 12 days.

  • Kelly first eats foods 1 and 2.
  • If there is no reaction after 5 days, she eats food 3. Five days after that she knows whether food 3 or food 4 is the one.
  • If the first experiment does give a reaction, she eats food 1 seven days after the first experiment. Five days after that she knows whether food 1 or food 2 is the one.

Examples5

  1. Example 1

    Input
    3
    4 5 7
    8 1 1
    1 23 32
    
    Expected output
    Case #1: 12
    Case #2: 3
    Case #3: 0
    
  2. Example 2

    Input
    1
    1 1 1
    
    Expected output
    Case #1: 0
    
  3. Example 3

    Input
    6
    1 1 1
    1 100 100
    1 1 100
    1 50 50
    1 7 99
    1 100 100
    
    Expected output
    Case #1: 0
    Case #2: 0
    Case #3: 0
    Case #4: 0
    Case #5: 0
    Case #6: 0
    
  4. Example 4

    Input
    8
    2 1 1
    2 100 100
    2 1 100
    2 99 100
    2 5 7
    3 5 7
    2 50 60
    2 1 2
    
    Expected output
    Case #1: 1
    Case #2: 100
    Case #3: 1
    Case #4: 99
    Case #5: 5
    Case #6: 10
    Case #7: 50
    Case #8: 1
    
  5. Example 5

    Input
    10
    2 1 1
    3 1 1
    4 1 1
    5 1 1
    8 1 1
    9 1 1
    1024 1 1
    1025 1 1
    1000000000000000 1 1
    999999999999999 1 1
    
    Expected output
    Case #1: 1
    Case #2: 2
    Case #3: 2
    Case #4: 3
    Case #5: 3
    Case #6: 4
    Case #7: 10
    Case #8: 11
    Case #9: 50
    Case #10: 50