#abc350e. E - Toward 0

E - Toward 0

Score: 450450 points

问题陈述

给定一个整数 NN。你可以执行以下两种类型的操作:

  • 支付 XX 日元将 NN 替换为 NA\displaystyle\left\lfloor\frac{N}{A}\right\rfloor
  • 支付 YY 日元掷一个骰子(一对骰子),骰子显示的整数在 1166 之间,包括 1166,概率相等。设 bb 为骰子的结果,并将 NN 替换为 Nb\displaystyle\left\lfloor\frac{N}{b}\right\rfloor

这里,s\lfloor s \rfloor 表示小于或等于 ss 的最大整数。例如,3=3\lfloor 3 \rfloor=32.5=2\lfloor 2.5 \rfloor=2

确定在 NN 变为 00 之前,通过最优选择操作支付的最小预期成本。每次操作中骰子的结果独立于其他掷骰,并且可以在观察到前一次操作的结果后做出操作的选择。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer NN. You can perform the following two types of operations:

  • Pay XX yen to replace NN with NA\displaystyle\left\lfloor\frac{N}{A}\right\rfloor.
  • Pay YY yen to roll a die (dice) that shows an integer between 11 and 66, inclusive, with equal probability. Let bb be the outcome of the die, and replace NN with Nb\displaystyle\left\lfloor\frac{N}{b}\right\rfloor.

Here, s\lfloor s \rfloor denotes the greatest integer less than or equal to ss. For example, 3=3\lfloor 3 \rfloor=3 and 2.5=2\lfloor 2.5 \rfloor=2.

Determine the minimum expected cost paid before NN becomes 00 when optimally choosing operations.
The outcome of the die in each operation is independent of other rolls, and the choice of operation can be made after observing the results of the previous operations.

Constraints

  • 1N10181 \leq N \leq 10^{18}
  • 2A62 \leq A \leq 6
  • 1X,Y1091 \leq X, Y \leq 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN AA XX YY

Output

Print the answer.
Your output will be considered correct if the absolute or relative error from the true answer is at most 10610^{-6}.

Sample Input 1

3 2 10 20

Sample Output 1

20.000000000000000

The available operations are as follows:

  • Pay 1010 yen. Replace NN with N2\displaystyle\left\lfloor\frac{N}{2}\right\rfloor.
  • Pay 2020 yen. Roll a die. Let bb be the outcome, and replace NN with Nb\displaystyle\left\lfloor\frac{N}{b}\right\rfloor.

The optimal strategy is to perform the first operation twice.

Sample Input 2

3 2 20 20

Sample Output 2

32.000000000000000

The available operations are as follows:

  • Pay 2020 yen. Replace NN with N2\displaystyle\left\lfloor\frac{N}{2}\right\rfloor.
  • Pay 2020 yen. Roll a die. Let bb be the outcome, and replace NN with Nb\displaystyle\left\lfloor\frac{N}{b}\right\rfloor.

The optimal strategy is as follows:

  • First, perform the second operation to roll the die.
    • If the outcome is 44 or greater, then NN becomes 00.
    • If the outcome is 22 or 33, then NN becomes 11. Now, perform the first operation to make N=0N = 0.
    • If the outcome is 11, restart from the beginning.

Sample Input 3

314159265358979323 4 223606797 173205080

Sample Output 3

6418410657.7408381