Subfactorial
The subfactorial, also known as the derangement number or the coincidence number, is a combinatorial function that counts the number of permutations of a set of objects such that no object appears in its original position. It is often denoted by !n or D_n, where n is a non-negative integer.
For a set of size n, a derangement is a permutation p where for all elements i
The subfactorial can be calculated using a recursive formula: !n = (n-1) * (!(n-1) + !(n-2)) for n >= 2,
The subfactorial function grows rapidly with n. The first few values are !0 = 1, !1 = 0,