Premium problem91. Nothing In Its Original Place

Medium Locked

Shuffle n items uniformly at random. Return the probability that no item ends up where it started, which is called a derangement.

P=∑j=0n(−1)jj!P = \sum_{j=0}^{n} \frac{(-1)^j}{j!}

The answer converges to 1/e≈0.36791/e \approx 0.3679 almost immediately, and barely moves after n = 5 no matter how large n gets.

Input

5

Output

0.3666666666666667

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)