No.75 Expected Number of Rolls Problem
タグ : / 解いたユーザー数 222
作問者 :
nmnmnmnmnmnmnm
Problem Statement
You want to roll one die some number of times to make the sum of the rolled values exactly K.
If the sum exceeds K, the sum is reset to 0.
However, the number of rolls made is not reset.
For example, suppose K=5 and you roll the die once and get a 6.
In this case the sum has exceeded K, so the sum goes back to 0 and you proceed to the second roll.
You keep rolling the die until the sum of the rolled values is exactly K.
Find the expected number of times the die is rolled.
Input
K
K is a positive integer. 1\(\le\)K\(\le\)200.
Output
Output the expected value on one line. An absolute or relative error of up to ±0.01 is accepted.
Do not forget the newline at the end.
Sample
Sample 1
Input
1
Output
6
It can be regarded that exactly 1 does not come up unless the die is rolled 6 times.
Sample 2
Input
2
Output
6
If you think of it as a trial of rolling a 2 with probability 1/6, it can be regarded that about 6 rolls will make the sum exactly 2.
Even if a 1 comes up first, you then only need to roll a 1 with probability 1/6, so the situation does not change at all.
Sample 3
Input
3
Output
6
Sample 4
Input
7
Output
9.94315
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。