login
A324375
Number of permutations p of [n] whose absolute displacements |p(i)-i| are square numbers.
4
1, 1, 2, 3, 5, 13, 29, 68, 165, 339, 1249, 3706, 11749, 39151, 105714, 321361, 938529, 4112583, 16778058, 64073812, 260625900, 917269164, 3451696842, 13068376545, 48655092849
OFFSET
0,3
EXAMPLE
a(3) = 3: 123, 132, 213.
a(4) = 5: 1234, 1243, 1324, 2134, 2143.
a(5) = 13: 12345, 12354, 12435, 13245, 13254, 21345, 21354, 21435, 23451, 51234, 52341, 52431, 53241.
MAPLE
b:= proc(s) option remember; (n-> `if`(n=0, 1, add(`if`(
issqr(abs(n-j)), b(s minus {j}), 0), j=s)))(nops(s))
end:
a:= n-> b({$1..n}):
seq(a(n), n=0..16);
MATHEMATICA
b[s_] := b[s] = Function[n, If[n == 0, 1, Sum[If[IntegerQ@Sqrt[Abs[n-j]], b[s ~Complement~ {j}], 0], {j, s}]]][Length[s]];
a[n_] := b[Range[n]];
a /@ Range[0, 16] (* Jean-François Alcover, Apr 23 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Feb 25 2019
STATUS
approved