Expected Number of Random Moves

Problem #418

Tags: mathematics simple random dynamic-programming

Who solved this?

No translations... yet
illustration of toy turtle crawling along the inch ruler

Thanks to Kevin Bodurtha for this tiny and curious math problem!

Let's imagine a number line of sequential integer values labeled 0 to n. We take a stone and place it on 0, so the stone's position is p = 0. We then use a random number generator to obtain a random value r in the range [1, n - p], and then we reposition the stone to the new value p + r, repeating the process until the stone is positioned at n.

For a number line of length n, the minimum possible amount of moves it could take to reach the end would be 1, if the first roll yielded n. The maximum amount of moves it could take would be n, if each roll only yielded 1.

What is the expected value of moves required to reach the end of a number line of length n?

Problem Statement

Input data gives the number of testcases (T) in the first line.
The second line will consist of T integer values for n separated by spaces.

Answer should contain T space-separated decimal values corresponding to the expected values of turns required to reach the end of a number line of length n. Precision of 1e-8 should be enough.

Example

input data:
3
2 4 10

answer:
1.5 2.08333333 2.92896825
You need to login to get test data and submit solution.