题目描述
Problem Description
There is an integer x selected uniformly at random within the range [0, n). We need to find an integer y within the range [0, n) such that x ⊕ y is maximized. Here, ⊕ represents the XOR operation.
The issue is that x might have been encrypted. Intelligence indicates that the probability of x not being encrypted is p. We decide on the following strategy: if x is not encrypted, we choose y that maximizes x ⊕ y; otherwise, we select an integer y uniformly at random within the range [0, n).
You are required to calculate the expected value of x ⊕ y.
Input Format
The input file contains a single line with a positive integer n and a real number p, as described in the problem statement. p is accurate to at most six decimal places.
Output Format
Output a single line representing the expected value of x ⊕ y. Your output will be considered correct only if the relative error with the standard output does not exceed $10^{-5}$. It is recommended to keep at least six decimal places.
Sample Input and Output
Sample Input #1
3 0.5
Sample Output #1
2.000000
Sample Input #2
123456 0.5
Sample Output #2
98063.674346
Notes
Consider Sample 1. If x is not encrypted, the possible values of x and the corresponding y are as follows:
The expected value at this time is 8/3.
If x is encrypted, the possible values of x and y are as follows:
The expected value at this time is 12/9 = 4/3.
Therefore, the total expected value is 2.
The data scale for all test points is as follows:
For all test data, $1 \le n \le 10^{18}$.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分