login
A324372
Number of permutations p of [n] whose absolute displacements |p(i)-i| are prime numbers.
4
1, 0, 0, 0, 1, 2, 9, 28, 144, 640, 2348, 6740, 37161, 208186, 1410137, 8322892, 47973920, 231922220, 1747678465, 11712495736, 101585559496, 776251710048, 6154289307912, 41248110305520, 397850617247393
OFFSET
0,6
EXAMPLE
a(4) = 1: 3412.
a(5) = 2: 34512, 45123.
a(6) = 9: 345621, 351624, 356124, 451623, 456123, 456231, 645123, 645231, 651234.
MAPLE
b:= proc(s) option remember; (n-> `if`(n=0, 1, add(`if`(
isprime(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] = With[{n = Length[s]}, If[n==0, 1, Sum[If[
PrimeQ[Abs[n-j]], b[s ~Complement~ {j}], 0], {j, s}]]];
a[n_] := b[Range[n]];
a /@ Range[0, 16] (* Jean-François Alcover, Mar 25 2021, after Alois P. Heinz *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Alois P. Heinz, Feb 25 2019
STATUS
approved