ZeroShark and Magician
Difficulty: Hard

ZeroShark has $T$ numbers, $n_1, ..., n_T$, that he wants a magic trick to be performed on.

Wet Shark will take each of these numbers, and do magic tricks on them.

Wet Shark will perform the following magic trick: For an integer $x$, Wet Shark will replace this integer with a new integer $x_1$, randomly chosen from $0$ to $x-1$, inclusive. He will then replace $x_1$ with an integer $x_2$, chosen from $0$ to $x_1-1$, inclusive. He will repeat this process until he reaches an integer $x_i = 0$. Calculate the expected value of $i$ for each number $n_i$.

For example, if $x=3$, the replacement sequences can go as follows: 

$x = 3, x_1 = 2, x_2 = 1, x_3 = 0$

$x = 3, x_1 = 2, x_2 = 0$

$x = 3, x_1 = 1, x_2 = 0$

$x = 3, x_1 = 0$

The probability of picking the first replacement sequence is $\frac{1}{3} \cdot \frac{1}{2}  = \frac{1}{6}$, because the probability that $x_1 = 2$ is equal to $\frac{1}{3}$ and the probability that $x_2 = 1$ is $\frac{1}{2}$, after $x_1 = 2$. The probability of the 2nd, 3rd, and 4th sequences can be similarly calculated as $\frac{1}{6}, \frac{1}{3},$ and $\frac{1}{3}$, respectively. The expected value is then $3 * 1/6 + 2 * 1/6 + 2 * 1/3 + 1 * 1/3 = \frac{11}{6}$.


Input Format:
The first line contains an integer $T (1 \le T \le 100)$, representing the number of integers ZeroShark wants a magic trick to be performed on.

The next $T$ lines of the input contain integers $1 \le n_1, ..., n_T \le 3 \cdot 10^5$, representing the integers Wet Shark wants magic tricks performed on.


Output Format:
Output $T$ lines, each containing the expected value of $i$ for each starting value $x = n_i$. Your answers will be considered correct if their absolute or relative error does not exceed $10^{-5}$.


Sample Input:
    2
    2
    3

Sample Output:
    1.5
    1.8333333333333333

Python 3 starter code:


Reference solution (Unknown):
    tcs = int(input())
    tc = [int(input()) for _ in range(tcs)]

    n = max(tc)
    dp = [0] * (n + 1)
    x = 0
    sumx = 0
    for i in range(1, n+1):
        x = 1/i * sumx + 1
        sumx += x
        dp[i] = x
    for i in tc:
        print(dp[i])