A set of disks numbered
through are placed in a line in
random order.
What is the probability that we have a partial derangement such that
exactly prime number discs are
found away from their natural positions? (Any number of non-prime disks
may also be found in or out of their natural positions.)
Give your answer rounded to
places behind the decimal point in the form .
fac = [1] for i inrange(1, N + 1): fac.append(fac[-1] * i) f = [[0for x inrange(y + 1)] for y inrange(N + 1)] # A047920 for i inrange(N + 1): f[i][0] = fac[i] for j inrange(1, i + 1): f[i][j] = f[i][j - 1] - f[i - 1][j - 1] ans = C(M, O) * f[N - (M - O)][O] / fac[N] print("{:.12f}".format(ans))