Candy Store (Large)

Choose the fewest box sizes so any sequence of up to k orders of 1 to C grams can be paid exactly with whole boxes.

Medium7GreedyMathNo attempts yetTime limit5sMemory limit512 MB

Problem

Running a candy store means optimizing a lot of things. The candy that sells best right now is the Whizbopper, and it goes rotten very quickly, which forces two rules on you.

  • Every morning you buy fresh Whizboppers from your supplier.
  • You sell Whizboppers in the boxes you bought that morning.

You can order boxes that contain any integer number of grams. A box cannot be opened or split, so a customer always receives whole boxes.

Up to kk customers visit the store in one day. Starting with the first one, each customer picks an integer amount between 11 and CC cents and buys that much candy. Candy sells for 11 cent per gram, so a customer who spends 44 cents gets exactly 44 grams. You can hand over one 44 gram box, or one 22 gram box and two 11 gram boxes.

What is the smallest number of boxes you have to order in the morning so that every customer gets exactly the mass they ask for, whatever the amounts turn out to be?

Note: when a customer picks an amount, you know what the earlier customers bought, but you do not know what the later customers will buy.

For example, suppose at most two customers come in a day and each spends at most 22 cents (k=2k=2, C=2C=2). Four 11 gram boxes work, but three boxes are enough: two 11 gram boxes and one 22 gram box. Hand them out like this.

First customerBoxes givenSecond customerBoxes given
2 centsone 2 gram box2 centstwo 1 gram boxes
2 centsone 2 gram box1 centone 1 gram box
1 centone 1 gram box2 centsone 2 gram box
1 centone 1 gram box1 centone 1 gram box

Whatever the first customer picks, the second customer still gets an exact mass, so three boxes cover every order sequence for k=2k=2, C=2C=2. For k=1k=1, C=5C=5, one 11 gram box and two 22 gram boxes are enough.

Input

The first line contains the number of test cases TT. Each of the next TT lines contains two integers kk and CC, the largest number of customers in a day and the largest amount one customer may spend.

Limits

  • 1T1001 \le T \le 100
  • 1k10001 \le k \le 1000
  • 1C10121 \le C \le 10^{12}

Output

For each test case, print one line in the form "Case #x: y", where xx is the test case number starting from 11 and yy is the minimum number of boxes you need to order every morning.