Combine The Gears
Time limit2sMemory limit256 MB
Given a budget b, choose gear sizes with total cost at most b to maximize the number of distinct pointer-direction tuples, output as a natural logarithm.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
As society develops quickly, the demand for high-precision clocks keeps rising. Recently, the China Clock Production Company has been developing a new type of clock that can represent a wide range of times.
This novel clock displays the current time in an unusual way. The clock consists of several pointers, each controlled by one gear. All gears rotate in sync, advancing one tooth per period. The gears may have different numbers of teeth, though. If a gear has teeth, the pointer it controls can point in different directions, denoted , where is the initial direction. Moreover, if a clock has pointers and the -th pointer is controlled by a gear with teeth, then after periods the -th pointer points to .
A gear with teeth costs yuan. Given a total budget of yuan, you must design a combination of gears that maximizes the number of valid combinations of pointer directions, while the total cost of the gears does not exceed the budget. A combination of directions is valid if it can be written as for some nonnegative integer , where is the number of teeth of the -th gear. Since the answer may be too large, output it as a natural logarithm (logarithm with base ).
Input
The first line of input contains a single integer , the number of test cases. Each test case is a single line containing an integer , the total budget.
Output
For each test case, print on a single line the natural logarithm of the maximum number of valid combinations, with an absolute or relative error of no more than .
Hint
For the second sample case, a 3-tooth gear together with a 4-tooth gear yields 12 different combinations of directions, and the total cost is exactly 7. So you should print the value of , which is approximately 2.484906650.