cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A242528 Number of cyclic arrangements of {0,1,...,n-1} such that both the difference and the sum of any two neighbors are prime.

This page as a plain text file.
%I A242528 #16 Oct 23 2018 03:03:02
%S A242528 0,0,0,0,0,0,0,0,0,0,0,2,4,18,13,62,8,133,225,209,32,2644,4462,61341,
%T A242528 113986,750294,176301,7575912,3575686,7705362,36777080,108638048,
%U A242528 97295807
%N A242528 Number of cyclic arrangements of {0,1,...,n-1} such that both the difference and the sum of any two neighbors are prime.
%C A242528 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.
%C A242528 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.
%H A242528 S. Sykora, <a href="http://dx.doi.org/10.3247/SL5Math14.002">On Neighbor-Property Cycles</a>, <a href="http://ebyte.it/library/Library.html#math">Stan's Library</a>, Volume V, 2014.
%e A242528 For n=12 (the first n for which a(n)>0) there are two such cycles:
%e A242528 C_1={0, 5, 2, 9, 4, 1, 6, 11, 8, 3, 10, 7},
%e A242528 C_2={0, 7, 10, 3, 8, 5, 2, 9, 4, 1, 6, 11}.
%t A242528 A242528[n_] :=
%t A242528 Count[Map[lpf, Map[j0f, Permutations[Range[n - 1]]]], 0]/2;
%t A242528 j0f[x_] := Join[{0}, x, {0}];
%t A242528 lpf[x_] := Length[
%t A242528    Join[Select[asf[x], ! PrimeQ[#] &],
%t A242528     Select[Differences[x], ! PrimeQ[#] &]]];
%t A242528 asf[x_] := Module[{i}, Table[x[[i]] + x[[i + 1]], {i, Length[x] - 1}]];
%t A242528 Table[A242528[n], {n, 1, 8}]
%t A242528 (* OR, a less simple, but more efficient implementation. *)
%t A242528 A242528[n_, perm_, remain_] := Module[{opt, lr, i, new},
%t A242528    If[remain == {},
%t A242528      If[PrimeQ[First[perm] - Last[perm]] &&
%t A242528        PrimeQ[First[perm] + Last[perm]], ct++];
%t A242528      Return[ct],
%t A242528      opt = remain; lr = Length[remain];
%t A242528      For[i = 1, i <= lr, i++,
%t A242528       new = First[opt]; opt = Rest[opt];
%t A242528       If[! (PrimeQ[Last[perm] - new] && PrimeQ[Last[perm] + new]),
%t A242528        Continue[]];
%t A242528       A242528[n, Join[perm, {new}],
%t A242528        Complement[Range[n - 1], perm, {new}]];
%t A242528       ];
%t A242528      Return[ct];
%t A242528      ];
%t A242528    ];
%t A242528 Table[ct = 0; A242528[n, {0}, Range[n - 1]]/2, {n, 1, 18}]
%t A242528 (* _Robert Price_, Oct 22 2018 *)
%o A242528 (C++) See the link.
%Y A242528 Cf. A227050, A242519, A242520, A242521, A242522, A242523, A242524, A242525, A242526, A242527, A242529, A242530, A242531, A242532, A242533, A242534.
%K A242528 nonn,hard,more
%O A242528 1,12
%A A242528 _Stanislav Sykora_, May 30 2014
%E A242528 a(29)-a(33) from _Fausto A. C. Cariboni_, May 20 2017