QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#7962. Prefix Sum

Statistics

Xiao Lan likes random numbers very much.

She first selects a real number $0 < p < 1$, and then generates $n$ random numbers $x_1, \dots, x_n$, where each number is independently generated as follows:

  • $x_i$ is $1$ with probability $p$, $2$ with probability $(1-p)p$, $3$ with probability $(1-p)^2p$, and so on.

After generating these random numbers, Xiao Ai calculates the prefix sums of the sequence to obtain the sequence $y_1, \dots, y_n$.

Given $1 \leq l \leq r \leq n$, Xiao Lan wants to know the expected number of $y_i$ that fall within the range $[l, r]$.

Input

Read the data from standard input.

A single line containing four numbers $n, p, l, r$. It is guaranteed that $1 \leq l \leq r \leq n \leq 10^9$, and the number of decimal places of $p$ does not exceed $6$.

Output

Output to standard output.

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

Examples

Input 1

3 0.5 1 2

Output 1

1.000000

Note 1

With probability $1/4$, $x_1=1$ and $x_2>1$, in which case only $y_1$ falls within $[1, 2]$.

With probability $1/4$, $x_1=1$ and $x_2=1$, in which case $y_1, y_2$ fall within $[1, 2]$.

With probability $1/4$, $x_1=2$, in which case only $y_1$ falls within $[1, 2]$.

Therefore, the expectation is $1/4 \cdot (1 + 2 + 1) = 1$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.