#P5147. 随机数生成器
随机数生成器
Description
HKE recently wrote a function , where are positive integers and . This function returns, with equal probability, any positive integer in the interval . Then he wrote another function:
int work(int x){
if(x==1) return 0;
else return work(rand(1,x))+1;
}
In Pascal, this code is:
function work(x:integer):integer;
begin
if x=1 then exit(0);
else exit(work(rand(1,x))+1);
end;
Given a positive integer , what is the expected value of the return value of ?
Definition of expectation: Suppose all possible return values of are with probabilities , then the expectation is:
Input Format
A positive integer .
Output Format
A real number representing the expected value of . Keep decimal places.
2
2.00000
3
2.50000
100000
13.09014
Hint
[Sample 1 Explanation]
returns with probability , returns with probability , returns with probability , and so on.
Therefore, the expectation is .
Constraints
For of the testdata, ;
For of the testdata, ;
For of the testdata, ;
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号