login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A242527 Number of cyclic arrangements (up to direction) of {0,1,...,n-1} such that the sum of any two neighbors is a prime. 20
0, 0, 0, 0, 1, 1, 2, 6, 6, 22, 80, 504, 840, 6048, 3888, 37524, 72976, 961776, 661016, 11533030, 7544366, 133552142, 208815294, 5469236592, 6429567323, 153819905698, 182409170334, 4874589558919, 7508950009102, 209534365631599 (list; graph; refs; listen; history; text; internal format)
OFFSET
1,7
COMMENTS
a(n)=NPC(n;S;P) is the count of all neighbor-property cycles for a specific set S={0,1,...,n-1} of n elements and a specific pair-property P. For more details, see the link and A242519.
For the same pair-property P but the set {1 through n}, see A051252. Using for pair-property the difference, rather than the sum, one obtains A228626.
LINKS
S. Sykora, On Neighbor-Property Cycles, Stan's Library, Volume V, 2014.
EXAMPLE
The first such cycle is of length n=5: {0,2,1,4,3}.
The first case with 2 solutions is for cycle length n=7:
C_1={0,2,3,4,1,6,5}, C_2={0,2,5,6,1,4,3}.
The first and the last of the 22 such cycles of length n=10 are:
C_1={0,3,2,1,4,9,8,5,6,7}, C_22={0,5,8,9,4,3,2,1,6,7}.
MATHEMATICA
A242527[n_] := Count[Map[lpf, Map[j0f, Permutations[Range[n - 1]]]], 0]/2;
j0f[x_] := Join[{0}, x, {0}];
lpf[x_] := Length[Select[asf[x], ! PrimeQ[#] &]];
asf[x_] := Module[{i}, Table[x[[i]] + x[[i + 1]], {i, Length[x] - 1}]];
Table[A242527[n], {n, 1, 10}]
(* OR, a less simple, but more efficient implementation. *)
A242527[n_, perm_, remain_] := Module[{opt, lr, i, new},
If[remain == {},
If[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], Continue[]];
A242527[n, Join[perm, {new}],
Complement[Range[n - 1], perm, {new}]];
];
Return[ct];
];
];
Table[ct = 0; A242527[n, {0}, Range[n - 1]]/2, {n, 1, 15}]
(* Robert Price, Oct 18 2018 *)
PROG
(C++) See the link.
CROSSREFS
Sequence in context: A320916 A119551 A100634 * A304680 A367765 A325803
KEYWORD
nonn,hard
AUTHOR
Stanislav Sykora, May 30 2014
EXTENSIONS
a(23)-a(30) from Max Alekseyev, Jul 09 2014
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 16 00:00 EDT 2024. Contains 371696 sequences. (Running on oeis4.)