OFFSET
0,3
LINKS
Wikipedia, Permutation
EXAMPLE
a(4) = 8: 1234, 1432, 2134, 2314, 2341, 4132, 4312, 4321.
a(5) = 4: 12345, 14325, 52341, 54321.
a(7) = 4: 1234567, 1654327, 7234561, 7654321.
a(13) = 12: 123456789(10)(11)(12)(13), 143256789(10)(11)(12)(13), 143(10)987652(11)(12)(13), 1(12)(11)256789(10)34(13), 1(12)(11)(10)98765234(13), 1(12)(11)(10)98765432(13), (13)23456789(10)(11)(12)1, (13)43256789(10)(11)(12)1, (13)43(10)987652(11)(12)1, (13)(12)(11)256789(10)341, (13)(12)(11)(10)987652341, (13)(12)(11)(10)987654321.
MAPLE
b:= proc(s, n) option remember; (m-> `if`(m=0, 1, `if`(irem(
mul(h, h=({$1..n} minus s)), (n-m)!)=0 and irem(mul(h,
h=s), m!)=0, add(b(s minus {j}, n), j=s), 0)))(nops(s))
end:
a:= n-> b({$1..n}, n):
seq(a(n), n=0..17);
MATHEMATICA
b[s_, n_] := b[s, n] = With[{m = Length[s]}, If[m == 0, 1, If[Mod[ Product[h, {h, Range[n] ~Complement~ s}], (n-m)!] == 0 && Mod[Times@@s, m!] == 0, Sum[b[s ~Complement~ {j}, n], {j, s}], 0]]];
a[n_] := b[Range[n], n];
Table[Print[n, " ", a[n]]; a[n], {n, 0, 27}] (* Jean-François Alcover, Nov 01 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Apr 09 2020
STATUS
approved