問題一覧 > 通常問題

No.75 Expected Number of Rolls Problem

レベル : / 実行時間制限 : 1ケース 5.000秒 / メモリ制限 : 512 MB / 小数誤差許容問題 絶対誤差または相対誤差が $10^{-2}$ 以下。ただし、ジャッジ側の都合で500桁未満にしてください
タグ : (AC するまで非表示) / 解いたユーザー数 222
作問者 : nmnmnmnmnmnmnm
お気に入りにしたユーザー ProblemId : 129 / 自分の提出
問題文最終更新日: 2026-06-25 10:35:37
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 56 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。