2094. 前缀和/Sum

小兰很喜欢随机数。

TA 首先选定了一个实数 0<p<10 < p < 1,然后生成了 nn 个随机数 x1,,xnx_1,\dots,x_n,每个数是独立按照如下方式生成的:

  • xix_ipp 的概率是 11,有 (1p)p(1-p)p 的概率是 22,有 (1p)2p(1-p)^2p 的概率是 33,以此类推。

生成完这些随机数之后,小艾对这个数列求了前缀和,得到了数列 y1,,yny_1,\dots,y_n

给定 1lrn1\leq l\leq r\leq n,小兰想知道,期望有多少 yiy_i 落在 [l,r][l, r] 内?

Ran loves random numbers.

Ran first selects a real number 0<p<10 < p < 1 and then generates nn random numbers x1,,xnx_1,\dots,x_n, each of which is generated independently as follows:

  • xix_i equals to pp with probability 11, (1p)p(1-p)p with probability 22, (1p)2p(1-p)^2p with probability 33, and so on.

After generating these random numbers, Ai summed the prefixes of this series to get the series y1,,yny_1,\dots,y_n.

Given 1lrn1\leq l\leq r\leq n, Lan wants to know how many yiy_i are expected to fall within [l,r][l, r]?

输入

一行输入四个数 n,p,l,rn, p, l, r。保证 1lrn1091\leq l\leq r\leq n\leq 10^9pp 的位数不超过 66

Enter four numbers n,p,l,rn, p, l, r on a line. Ensure that 1lrn1091\leq l\leq r\leq n\leq 10^9 and pp has no more than 66 digits.

输出

输出一个实数,表示答案。你需要保证答案的绝对或相对误差不超过 10610^{-6}

Output a real number representing the answer. You need to ensure that the absolute or relative error of the answer does not exceed 10610^{-6}.

样例

标准输入 复制文本
3 0.5 1 2
标准输出 复制文本
 1.000000

提示

1/41/4 的概率,x1=1x_1=1x2>1x_2>1,此时只有 y1y_1 落在 [1,2][1, 2] 内。

1/41/4 的概率,x1=1x_1=1x2=1x_2=1,此时 y1,y2y_1,y_2 落在 [1,2][1, 2] 内。

1/41/4 的概率,x1=2x_1=2,此时只有 y1y_1 落在 [1,2][1, 2] 内。

所以期望是 1/4(1+2+1)=11/4\cdot (1 + 2 + 1) = 1

With 1/41/4 probability, x1=1x_1=1 and x2>1x_2>1, only y1y_1 falls within [1,2][1, 2].

With 1/41/4 probability, x1=1x_1=1 and x2=1x_2=1, then y1,y2y_1,y_2 fall in [1,2][1, 2].

There is a 1/41/4 probability that x1=2x_1=2, when only y1y_1 falls within [1,2][1, 2].

So the expectation is 1/4(1+2+1)=11/4\cdot (1 + 2 + 1) = 1.

登录以提交代码。
单点时限 1 秒
内存限制 512 MB
提交 1
通过 1