A367704 Number of permutations of [n] where each pair of adjacent elements differs by a prime.
1, 1, 0, 0, 2, 10, 32, 96, 448, 1968, 7320, 21516, 118938, 662742, 4556360, 26950038, 155388246, 756995286, 5730299976, 38809702892, 337875402936, 2593543573702, 20560179519176, 138677553274430, 1337517942958934, 11083936316867572, 94288296012340842
Offset: 0
Keywords
Examples
a(4) = 2: 2413, 3142. a(5) = 10: 13524, 14253, 24135, 25314, 31425, 35241, 41352, 42531, 52413, 53142.
Links
Programs
-
PARI
okperm(perm) = {for (k=1, #perm -1, if (! isprime(abs(perm[k]-perm[k+1])), return (0)); ); return (1); } a(n) = {nbok = 0; for (j=1, n!, perm = numtoperm(n, j); if (okperm(perm), nbok++); ); return (nbok); }
Extensions
a(14)-a(22) from Alois P. Heinz, Nov 27 2023
a(23)-a(26) from Martin Ehrenstein, Dec 03 2023
Comments