OFFSET
0,3
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..450
Wikipedia, Permutation
FORMULA
a(n) = n! - A306524(n).
EXAMPLE
a(3) = 3: 123, 132, 213.
a(4) = 9: 1234, 1243, 1324, 2134, 2143, 2341, 4123, 4231, 4321.
a(5) = 34: 12345, 12354, 12435, 13245, 13254, 13452, 15234, 15342, 15432, 21345, 21354, 21435, 23415, 23451, 25314, 25341, 25431, 41235, 41352, 42315, 42351, 43215, 43251, 45231, 45312, 51234, 51342, 51432, 52314, 52341, 52431, 53214, 53241, 53412.
MATHEMATICA
b[s_, k_] := b[s, k] = With[{n = Length[s]}, If[n == 0, 1, Sum[If[Abs[i-n] == k, 0, b[s~Complement~{i}, k]], {i, s}]]];
A[n_, k_] := If[k >= n, n!, b[Range[n], k]];
a[n_] := A[n, 2];
Table[Print[n, " ", a[n]]; a[n], {n, 0, 23}] (* Jean-François Alcover, Oct 31 2021, after Alois P. Heinz in A306512 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Feb 21 2019
STATUS
approved