Breaking the Superconductor
Time limit2sMemory limit1024 MB
Find the minimum total cost to cut an N gram block into K pieces of at least 1 gram each, where each cut costs the weight of the piece being cut.
Problem
You developed a room-temperature, ambient-pressure superconductor and wrote a paper that will change the world. You have a block of superconductor weighing . To verify the paper, laboratories have asked for superconductor samples. Each laboratory needs a sample of at least . Fortunately, you have a technique for breaking superconductors precisely. For an integer with , a piece of can be cut as follows.
- Choose an integer with .
- Split the piece into one piece of and one piece of .
- The cut costs won.
To reduce research costs, you need to find the minimum cost of cutting the superconductor into pieces. You can assume that under the constraints, the superconductor can be split into pieces using the method above.
Input
The first line contains the number of test cases .
Each of the next lines contains two integers and , separated by a space. is the weight of the superconductor block, and is the number of laboratories that asked for samples.
Output
For each test case, print the minimum cost of cutting the superconductor into pieces.
Constraints
- All given numbers are integers.