#P5389. Cirno's Summation Game

    ID: 18621 Type: Default 1000ms 256MiB

Cirno's Summation Game

Cirno's Summation Game

Cirno has just started learning arithmetic and happily computed the sums from \(1\) all the way up to \(n\). She obtained the sequence:

\[ \{a_i = 1 + 2 + \cdots + i\} \quad \text{for } i = 1,2,\ldots, n \]

To check her calculations, she picks two elements \(v_1\) and \(v_2\) (they may be the same) from the sequence according to the following probability distribution. The probability of selecting the \(i\)th element \(a_i\) is given by:

\[ P(i) = \frac{a_i}{\sum_{k=1}^{n} a_k} = \frac{3i(i+1)}{n(n+1)(n+2)} \]

After selecting \(v_1\) and \(v_2\) (with the two choices independent), she uniformly chooses an integer \(a \in [1, v_1]\) and an integer \(b \in [1, v_2]\). Your task is to compute the overall probability that \(a > b\).

Note: For a given pair of selected elements with values \(v_1\) and \(v_2\), the probability that a uniformly chosen \(a \in [1,v_1]\) is greater than a uniformly chosen \(b \in [1,v_2]\) can be computed as follows:

  • If \(v_1 \le v_2\) (which happens when the index \(i \le j\)), then
    \[ P(a>b) = \frac{v_1 - 1}{2 v_2} \] (with the special case when \(v_1=1\), so that \(P(a>b)=0\)).
  • If \(v_1 > v_2\) (i.e. \(i > j\)), then
    \[ P(a>b) = \frac{2v_1 - v_2 - 1}{2 v_1} \]

Since \(v_i = \frac{i(i+1)}{2}\), you can substitute to obtain the following cases:

  • For \(i < j\):
    \[ P(a>b \mid i,j) = \frac{\frac{i(i+1)}{2} - 1}{j(j+1)} \]
  • For \(i = j\):
    \[ P(a>b \mid i,j) = \frac{\frac{i(i+1)}{2} - 1}{i(i+1)} \]
  • For \(i > j\):
    \[ P(a>b \mid i,j) = \frac{i(i+1) - \frac{j(j+1)}{2} - 1}{i(i+1)} \]

The overall probability is computed by summing over all pairs \((i,j)\) with the corresponding selection probabilities:

[ \text{Probability} = \sum_{i=1}^{n} \sum_{j=1}^{n} \left(\frac{3i(i+1)}{n(n+1)(n+2)}\right) \left(\frac{3j(j+1)}{n(n+1)(n+2)}\right) \cdot P(a>b \mid i,j). ]

Output the computed probability. It is recommended to use a floating-point output with at least 6 decimal places of precision.

inputFormat

The input consists of a single integer \(n\) (\(1 \le n \le 1000\) for example) on a single line.

outputFormat

Output the probability that \(a > b\) as a floating-point number with at least 6 decimal places.

sample

1
0.000000