12341. Square of fortune
A real number x is chosen uniformly
at random from the segment [0; n]. The player’s reward equals the square
of the chosen number: W = x2.
Compute the expected value of the reward.
Input. One real number n (0 ≤ n ≤
109).
Output. Print the expected value of the reward with at least 4
decimal digits.
|
Sample input |
Sample output |
|
10 |
33.333333 |
probability
The random variable X is
uniformly distributed on the segment [0; n]. The probability density function on this interval is
f(x) = ![]()
To find the expected value
of the reward E[W] = E[x2], we need to average x2
over all possible values of x:
E[x2] =
=
=
= ![]()
Example
For n = 10 the answer is
E[x2]
=
= 33.333333
Algorithm implementation
Read the input value n.
scanf("%lld", &n);
Compute and print the answer.
res = n * n / 3.0;
printf("%lf\n", res);