With the rapid development of society, the demand for high-precision clocks is constantly rising. Recently, the China Clock Production Company is developing a new type of clock, which can represent a wide range of times.
The novel clock displays the current time in an unusual fashion. The clock consists of several pointers, each controlled by a gear. All gears rotate synchronously – one tooth per period. However, the numbers of teeth of the gears may differ. If a gear has t teeth, then the corresponding pointer can point to t different directions, denoted 0,1,2,⋯,t−1, respectively, where 0 is the initial direction. Furthermore, if a clock is equipped with n pointers, the i-th of which is controlled by a ti -tooth gear, then the i-th pointer will point to k mod ti after k periods of time.
The price for a t-tooth gear is t yuan. Given a total budget of b yuan, you need to design a combination of gears, such that the number of valid combinations of directions of pointers is maximized, and the total cost on gears does not exceed the budget. A combination of directions (d1 ,d2 ,⋯,dn ) is valid, if it can be written for some nonnegative integer k, where ti is the number of teeth of the i-th gear. Since the answer may be too large, output the answer in natural logarithm (logarithm with base e=2.718281828⋯).
1<T<30000
1<b<30000
Sample Input:
3
2
7
10
Sample Output:
0.693147181
2.484906650
3.401197382
题目大意
T组数据,
给你一个n,让你找若干个数xi,使得x1+x2+…xi<=n,且lcm(x1,x2,…,xi)最大
输出log(lcm)
思路
对于一个数n,要使他的lcm最大,那么就要保证xi两两互质(这样才能没有浪费)
因此xi可以看成某个质数的p次方,且该质数只能选择一次,例如3和9不能同时选,因为这样无法保证互质
那么很显然,问题被抽象成了分组背包,每个质数为一组,组里为该质数的p次方,背包容量为n,每件物品的贡献为log(xi)
CODE
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MAXN 30050
LL read()