小兰很喜欢随机数。
TA 首先选定了一个实数 0 < p < 1,然后生成了 n 个随机数 x_1,\dots,x_n,每个数是独立按照如下方式生成的:
生成完这些随机数之后,小艾对这个数列求了前缀和,得到了数列 y_1,\dots,y_n。
给定 1\leq l\leq r\leq n,小兰想知道,期望有多少 y_i 落在 [l, r] 内?
Ran loves random numbers.
Ran first selects a real number 0 < p < 1 and then generates n random numbers x_1,\dots,x_n, each of which is generated independently as follows:
After generating these random numbers, Ai summed the prefixes of this series to get the series y_1,\dots,y_n.
Given 1\leq l\leq r\leq n, Lan wants to know how many y_i are expected to fall within [l, r]?
输入
一行输入四个数 n, p, l, r。保证 1\leq l\leq r\leq n\leq 10^9,p 的位数不超过 6。
Enter four numbers n, p, l, r on a line. Ensure that 1\leq l\leq r\leq n\leq 10^9 and p has no more than 6 digits.
输出
输出一个实数,表示答案。你需要保证答案的绝对或相对误差不超过 10^{-6}。
Output a real number representing the answer. You need to ensure that the absolute or relative error of the answer does not exceed 10^{-6}.
样例
标准输入 复制文本 |
3 0.5 1 2 |
标准输出 复制文本 |
1.000000 |
提示
有 1/4 的概率,x_1=1 而 x_2>1,此时只有 y_1 落在 [1, 2] 内。
有 1/4 的概率,x_1=1 且 x_2=1,此时 y_1,y_2 落在 [1, 2] 内。
有 1/4 的概率,x_1=2,此时只有 y_1 落在 [1, 2] 内。
所以期望是 1/4\cdot (1 + 2 + 1) = 1。
With 1/4 probability, x_1=1 and x_2>1, only y_1 falls within [1, 2].
With 1/4 probability, x_1=1 and x_2=1, then y_1,y_2 fall in [1, 2].
There is a 1/4 probability that x_1=2, when only y_1 falls within [1, 2].
So the expectation is 1/4\cdot (1 + 2 + 1) = 1.