login
A242528
Number of cyclic arrangements of {0,1,...,n-1} such that both the difference and the sum of any two neighbors are prime.
20
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 18, 13, 62, 8, 133, 225, 209, 32, 2644, 4462, 61341, 113986, 750294, 176301, 7575912, 3575686, 7705362, 36777080, 108638048, 97295807
OFFSET
1,12
COMMENTS
a(n)=NPC(n;S;P) is the count of all neighbor-property cycles for a specific set S of n elements and a specific pair-property P. For more details, see the link and A242519.
In this case the set is S={0 through n-1}. For the same pair-property P but the set S={1 through n}, see A227050.
EXAMPLE
For n=12 (the first n for which a(n)>0) there are two such cycles:
C_1={0, 5, 2, 9, 4, 1, 6, 11, 8, 3, 10, 7},
C_2={0, 7, 10, 3, 8, 5, 2, 9, 4, 1, 6, 11}.
MATHEMATICA
A242528[n_] :=
Count[Map[lpf, Map[j0f, Permutations[Range[n - 1]]]], 0]/2;
j0f[x_] := Join[{0}, x, {0}];
lpf[x_] := Length[
Join[Select[asf[x], ! PrimeQ[#] &],
Select[Differences[x], ! PrimeQ[#] &]]];
asf[x_] := Module[{i}, Table[x[[i]] + x[[i + 1]], {i, Length[x] - 1}]];
Table[A242528[n], {n, 1, 8}]
(* OR, a less simple, but more efficient implementation. *)
A242528[n_, perm_, remain_] := Module[{opt, lr, i, new},
If[remain == {},
If[PrimeQ[First[perm] - Last[perm]] &&
PrimeQ[First[perm] + Last[perm]], ct++];
Return[ct],
opt = remain; lr = Length[remain];
For[i = 1, i <= lr, i++,
new = First[opt]; opt = Rest[opt];
If[! (PrimeQ[Last[perm] - new] && PrimeQ[Last[perm] + new]),
Continue[]];
A242528[n, Join[perm, {new}],
Complement[Range[n - 1], perm, {new}]];
];
Return[ct];
];
];
Table[ct = 0; A242528[n, {0}, Range[n - 1]]/2, {n, 1, 18}]
(* Robert Price, Oct 22 2018 *)
PROG
(C++) See the link.
KEYWORD
nonn,hard,more
AUTHOR
Stanislav Sykora, May 30 2014
EXTENSIONS
a(29)-a(33) from Fausto A. C. Cariboni, May 20 2017
STATUS
approved