#P5308. Maximum Bonus in k Rounds

    ID: 18541 Type: Default 1000ms 256MiB

Maximum Bonus in k Rounds

Maximum Bonus in k Rounds

You are facing a challenge with n opponents. In each round, some opponents are eliminated and you receive a bonus equal to the ratio of the number of opponents eliminated to the total number of opponents participating in that round. In other words, if in a round there are \(N\) opponents and \(x\) of them are eliminated, you gain \(\frac{x}{N}\) of that round's bonus pool. Note that each round has a bonus pool of 1 unit.

For example, if a round has 10 opponents and 3 are eliminated, you will receive a bonus of \(\frac{3}{10}\) from that round.

Your goal is to defeat all \(n\) opponents in exactly \(k\) rounds. In each round, you can choose how many opponents to eliminate provided that at least one opponent remains for each upcoming round (until the final round, where all remaining opponents are eliminated). What is the maximum bonus you can obtain? Output the answer with exactly 9 digits after the decimal point.

Mathematical Explanation:

Let \(x_i\) be the number of opponents eliminated in round \(i\) and let \(r_i\) be the remaining opponents after round \(i\) with \(r_0=n\) and \(r_k=0\). In round \(i\), the bonus is \(\frac{x_i}{r_{i-1}}\). To maximize the total bonus, an optimal strategy is to eliminate as many opponents as possible in the early rounds while still leaving at least one opponent for each subsequent round. In particular, for rounds \(1 \leq i \leq k-1\), choose \[ x_i = r_{i-1} - (k-i),\] so that the remaining opponents become \[ r_i = k-i.\] Then the total bonus is: \[ S = \frac{n-k+1}{n} + \sum_{i=1}^{k-1} \frac{1}{i},\] where we define \(\sum_{i=1}^{0} \frac{1}{i} = 0\) for \(k = 1\).

inputFormat

The input consists of a single line containing two integers \(n\) and \(k\) (with \(1 \le k \le n \le 10^6\)), where \(n\) is the total number of opponents and \(k\) is the number of rounds in which you win the competition.

outputFormat

Output a single line with the maximum bonus you can obtain, printed with exactly 9 digits after the decimal point.

sample

10 2
1.900000000