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.

Showing 1-10 of 26 results. Next

A242527 Number of cyclic arrangements (up to direction) of {0,1,...,n-1} such that the sum of any two neighbors is a prime.

Original entry on oeis.org

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
Offset: 1

Views

Author

Stanislav Sykora, May 30 2014

Keywords

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.

Examples

			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}.
		

Crossrefs

Programs

  • 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 *)

Extensions

a(23)-a(30) from Max Alekseyev, Jul 09 2014

A103839 Number of permutations of (1,2,3,...,n) where each of the (n-1) adjacent pairs of elements sums to a prime.

Original entry on oeis.org

1, 2, 2, 8, 4, 16, 24, 60, 140, 1328, 2144, 17536, 23296, 74216, 191544, 2119632, 4094976, 24223424, 45604056, 241559918, 675603568, 8723487720, 22850057800, 285146572432, 859834538938, 8276479696196, 32343039694056, 429691823372130
Offset: 1

Views

Author

N. J. A. Sloane, Mar 30 2005

Keywords

Comments

The number of Hamiltonian paths in a graph of which the nodes represent the numbers (1,2,3,...,n) and the edges connect each pair of nodes that add up to a prime. - Bob Andriesse, Oct 04 2020
While A076220(n) > a(n) for 2A076220(n) / a(n) < A076220(n-1) / a(n-1). - Bob Andriesse, Dec 05 2023

Examples

			For n = 5, we have the 4 permutations and the sums of adjacent elements:
1,4,3,2,5 (1+4=5, 4+3=7, 3+2=5, 2+5=7)
3,4,1,2,5 (3+4=7, 4+1=5, 1+2=3, 2+5=7)
5,2,1,4,3 (5+2=7, 2+1=3, 1+4=5, 4+3=7)
5,2,3,4,1 (5+2=7, 2+3=5, 3+4=7, 4+1=5)
		

Crossrefs

Programs

  • Mathematica
    A103839[n_] := Count[Map[lpf, Permutations[Range[n]]], 0]
    lpf[x_] := Length[Select[asf[x], ! PrimeQ[#] &]];
    asf[x_] := Module[{i}, Table[x[[i]] + x[[i + 1]], {i, Length[x] - 1}]];
    Table[A103839[n], {n, 1, 9}] (* Robert Price, Oct 25 2018 *)
  • PARI
    okperm(perm) = {for (k=1, #perm -1, if (! isprime(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);} \\ Michel Marcus, Apr 08 2013

Formula

For n>1, a(n) = 2 * A051239(n).

Extensions

More terms from Max Alekseyev, Jan 04 2008
a(25)-a(28) from Giovanni Resta, Apr 01 2014

A228626 Number of Hamiltonian cycles in the undirected simple graph G_n with vertices 1,...,n which has an edge connecting vertices i and j if and only if |i-j| is prime.

Original entry on oeis.org

0, 0, 0, 0, 1, 2, 4, 16, 60, 186, 433, 2215, 11788, 76539, 414240, 2202215, 9655287, 69748712, 444195809, 3703859949, 26688275292, 201673532931, 1265944917365, 11801735916539, 92511897525830, 753795624276096, 5237677221537738, 41074291450736424, 280906738160126067
Offset: 1

Views

Author

Zhi-Wei Sun, Aug 28 2013

Keywords

Comments

Conjecture: a(n) > 0 for all n > 4. In other words, for each n = 5,6,... there is a permutation i_1,...,i_n of 1,...,n such that |i_1-i_2|, |i_2-i_3|, ..., |i_{n-1}-i_n| and |i_n-i_1| are all prime.
Note that this conjecture is different from the prime circle problem in A051252 though they look similar.
On August 30 2013, Yong-Gao Chen (from Nanjing Normal University) confirmed the conjecture for n > 12 as follows: If n = 2*k then G_n contains a Hamiltonian cycle (1,3,5,2,7,9,...,2k-5,2k-3,2k,2k-2,2k-4,2k-1,2k-6,2k-8,...,6,4);
if n = 2*k + 1 then G_n contains a Hamiltonian cycle
(1,3,5,2,7,9,...,2k-5,2k,2k-3,2k-1,2k+1,2k-2,2k-4,...,6,4).
We have got Chen's approval to include his proof here.

Examples

			a(5) = 1 since G_5 contains the unique Hamiltonian cycle (1,4,2,5,3).
a(6) = 2 since G_6 contains exactly two Hamiltonian cycles: (1,3,5,2,4,6) and (1,4,2,5,3,6).
a(7) = 4 since G_7 contains exactly four Hamiltonian cycles: (1,3,5,2,7,4,6), (1,3,5,7,2,4,6), (1,4,2,7,5,3,6) and (1,4,7,2,5,3,6).
a(8) = 16 since G_8 contains exactly 16 Hamiltonian cycles: (1,3,5,2,7,4,6,8), (1,3,5,7,2,4,6,8), (1,3,6,4,2,7,5,8), (1,3,6,4,7,2,5,8), (1,3,6,8,5,2,7,4), (1,3,6,8,5,7,2,4), (1,3,8,5,2,7,4,6), (1,3,8,5,7,2,4,6), (1,4,2,7,5,3,6,8), (1,4,2,7,5,3,8,6), (1,4,2,7,5,8,3,6), (1,4,7,2,5,3,6,8), (1,4,7,2,5,3,8,6), (1,4,7,2,5,8,3,6), (1,6,4,2,7,5,3,8), (1,6,4,7,2,5,3,8).
a(9) > 0 since (1,3,5,7,9,2,4,6,8) is a Hamiltonian cycle in G_9.
a(10) > 0 since (1,3,5,2,4,6,9,7,10,8) is a Hamiltonian cycle in G_{10}.
a(11) > 0 since (1,3,5,10,8,11,9,2,7,4,6) is a Hamiltonian cycle in G_{11}.
a(12) > 0 since (1,3,8,10,5,2,7,4,6,11,9,12) is a Hamiltonian cycle in G_{12}.
		

Crossrefs

Programs

  • Mathematica
    Table[Length[FindHamiltonianCycle[Graph[Flatten[Table[If[PrimeQ[Abs[i - j]], i \[UndirectedEdge] j, {}], {i, 1, n}, {j, i + 1, n}]]], Infinity]], {n, 1, 15}] (* Robert Price, Apr 04 2019 *)

Extensions

a(9)-a(17) from Alois P. Heinz, Aug 28 2013
a(18)-a(19) from Stanislav Sykora, May 30 2014
a(20)-a(29) from Max Alekseyev, Jul 04 2014

A228917 Number of undirected circular permutations i_0, i_1, ..., i_n of 0, 1, ..., n such that i_0+i_1, i_1+i_2, ...,i_{n-1}+i_n, i_n+i_0 are among those k with 6*k-1 and 6*k+1 twin primes.

Original entry on oeis.org

1, 1, 1, 2, 2, 2, 5, 2, 12, 39, 98, 526, 2117, 6663, 15043, 68403, 791581, 4826577, 19592777, 102551299, 739788968, 4449585790, 36547266589, 324446266072, 2743681178070
Offset: 1

Views

Author

Zhi-Wei Sun, Sep 08 2013

Keywords

Comments

Conjecture: a(n) > 0 for all n > 0.
This implies the twin prime conjecture, and it is similar to the prime circle problem mentioned in A051252.
For each n = 2,3,... construct an undirected simple graph T(n) with vertices 0,1,...,n which has an edge connecting two distinct vertices i and j if and only if 6*(i+j)-1 and 6*(i+j)+1 are twin primes. Then a(n) is just the number of Hamiltonian cycles contained in T(n). Thus a(n) > 0 if and only if T(n) is a Hamilton graph.
Zhi-Wei Sun also made the following similar conjectures for odd primes, Sophie Germain primes, cousin primes and sexy primes:
(1) For any integer n > 0, there is a permutation i_0, i_1, ..., i_n of 0, 1, ..., n such that i_0+i_1, i_1+i_2, ..., i_{n-1}+i_n, i_n+i_0 are integers of the form (p-1)/2, where p is an odd prime. Also, we may replace the above (p-1)/2 by (p+1)/4 or (p-1)/6; when n > 4 we may substitute (p-1)/4 for (p-1)/2.
(2) For any integer n > 2, there is a permutation i_0, i_1, ..., i_n of 0, 1,..., n such that i_0+i_1, i_1+i_2, ..., i_{n-1}+i_n, i_n+i_0 are integers of the form (p+1)/6, where p is a Sophie Germain prime.
(3) For any integer n > 3, there is a permutation i_0, i_1, ..., i_n of 0, 1,..., n such that i_0+i_1, i_1+i_2, ..., i_{n-1}+i_n, i_n+i_0 are among those integers k with 6*k+1 and 6*k+5 both prime.
(4) For any integer n > 4, there is a permutation i_0, i_1, ..., i_n of 0, 1,..., n such that i_0+i_1, i_1+i_2, ..., i_{n-1}+i_n, i_n+i_0 are among those integers k with 2*k-3 and 2*k+3 both prime.

Examples

			a(n) = 1 for n = 1,2,3 due to the permutation (0,...,n).
a(4) = 2 due to the permutations (0,1,4,3,2) and (0,2,1,4,3).
a(5) = 2 due to the permutations (0,1,4,3,2,5), (0,3,4,1,2,5).
a(6) = 2 due to the permutations
  (0,1,6,4,3,2,5) and (0,3,4,6,1,2,5).
a(7) = 5 due to the permutations
  (0,1,6,4,3,2,5,7), (0,1,6,4,3,7,5,2), (0,2,1,6,4,3,7,5),
  (0,3,4,6,1,2,5,7), (0,5,2,1,6,4,3,7).
a(8) = 2 due to the permutations
  (0,1,6,4,8,2,3,7,5) and (0,1,6,4,8,2,5,7,3).
a(9) = 12 due to the permutations
  (0,1,6,4,3,9,8,2,5,7), (0,1,6,4,8,9,3,2,5,7),
  (0,1,6,4,8,9,3,7,5,2), (0,2,1,6,4,8,9,3,7,5),
  (0,2,8,9,1,6,4,3,7,5), (0,3,4,6,1,9,8,2,5,7),
  (0,3,9,1,6,4,8,2,5,7), (0,3,9,8,4,6,1,2,5,7),
  (0,5,2,1,6,4,8,9,3,7), (0,5,2,8,4,6,1,9,3,7),
  (0,5,2,8,9,1,6,4,3,7), (0,5,7,3,9,1,6,4,8,2).
a(10) > 0 due to the permutation (0,5,2,3,9,1,6,4,8,10,7).
a(11) > 0 due to the permutation (0,10,8,9,3,7,11,6,4,1,2,5).
a(12) > 0 due to the permutation
        (0, 5, 2, 1, 6, 4, 3, 9, 8, 10, 7, 11, 12).
		

Crossrefs

Programs

  • Mathematica
    (* A program to compute required circular permutations for n = 7. To get "undirected" circular permutations, we should identify a circular permutation with the one of the opposite direction; for example, (0,7,5,2,3,4,6,1) is identical to (0,1,6,4,3,2,5,7) if we ignore direction. Thus a(7) is half of the number of circular permutations yielded by this program. *)
    tp[n_]:=tp[n]=PrimeQ[6n-1]&&PrimeQ[6n+1]
    V[i_]:=Part[Permutations[{1,2,3,4,5,6,7}],i]
    m=0
    Do[Do[If[tp[If[j==0,0,Part[V[i],j]]+If[j<7,Part[V[i],j+1],0]]==False,Goto[aa]],{j,0,7}];
    m=m+1;Print[m,":"," ",0," ",Part[V[i],1]," ",Part[V[i],2]," ",Part[V[i],3]," ",Part[V[i],4]," ",Part[V[i],5]," ",Part[V[i],6]," ",Part[V[i],7]];Label[aa];Continue,{i,1,7!}]

Extensions

a(10)-a(25) from Max Alekseyev, Sep 12 2013

A228956 Number of undirected circular permutations i_0, i_1, ..., i_n of 0, 1, ..., n such that all the 2*n+2 numbers |i_0 +/- i_1|, |i_1 +/- i_2|, ..., |i_{n-1} +/- i_n|, |i_n +/- i_0| have the form (p-1)/2 with p an odd prime.

Original entry on oeis.org

1, 1, 1, 1, 5, 9, 17, 84, 30, 127, 791, 2404, 11454, 27680, 25942, 137272, 515947, 2834056, 26583034, 82099932, 306004652, 4518630225, 11242369312, 8942966426, 95473633156, 533328765065
Offset: 1

Views

Author

Zhi-Wei Sun, Sep 09 2013

Keywords

Comments

Conjecture: a(n) > 0 for all n > 0.
Note that if i-j = (p-1)/2 and i+j = (q-1)/2 for some odd primes p and q then 4*i+2 is the sum of the two primes p and q. So the conjecture is related to Goldbach's conjecture.
Zhi-Wei Sun also made the following similar conjecture: For any integer n > 5, there exists a circular permutation i_0, i_1, ..., i_n of 0, 1, ..., n such that all the 2*n+2 numbers 2*|i_k-i_{k+1}|+1 and 2*(i_k+i_{k+1})-1 (k = 0,...,n) (with i_{n+1} = i_0) are primes.

Examples

			a(n) = 1 for n = 1,2,3 due to the natural circular permutation (0,...,n).
a(4) = 1 due to the circular permutation (0,1,4,2,3).
a(5) = 5 due to the circular permutations (0,1,2,4,5,3), (0,1,4,2,3,5), (0,1,4,5,3,2), (0,2,1,4,5,3), (0,3,2,1,4,5).
a(6) = 9 due to the circular permutations
  (0,1,2,4,5,3,6), (0,1,2,4,5,6,3), (0,1,4,2,3,5,6),
  (0,1,4,2,3,6,5), (0,1,4,5,6,3,2), (0,2,1,4,5,3,6),
  (0,2,1,4,5,6,3), (0,3,2,1,4,5,6), (0,5,4,1,2,3,6).
a(7) = 17 due to the circular permutations
  (0,1,2,7,4,5,3,6), (0,1,2,7,4,5,6,3), (0,1,4,7,2,3,5,6),
  (0,1,4,7,2,3,6,5), (0,1,7,2,4,5,3,6), (0,1,7,2,4,5,6,3),
  (0,1,7,4,2,3,5,6), (0,1,7,4,2,3,6,5), (0,1,7,4,5,6,3,2),
  (0,2,1,7,4,5,3,6), (0,2,1,7,4,5,6,3), (0,2,7,1,4,5,3,6),
  (0,2,7,1,4,5,6,3), (0,3,2,1,7,4,5,6), (0,3,2,7,1,4,5,6),
  (0,5,4,1,7,2,3,6), (0,5,4,7,1,2,3,6).
		

Crossrefs

Programs

  • Mathematica
    (* A program to compute required circular permutations for n = 7. To get "undirected" circular permutations, we should identify a circular permutation with the one of the opposite direction; for example, (0,6,3,5,4,7,2,1) is identical to (0,1,2,7,4,5,3,6) if we ignore direction. Thus a(7) is half of the number of circular permutations yielded by this program. *)
    p[i_,j_]:=PrimeQ[2*Abs[i-j]+1]&&PrimeQ[2(i+j)+1]
    V[i_]:=Part[Permutations[{1,2,3,4,5,6,7}],i]
    m=0
    Do[Do[If[p[If[j==0,0,Part[V[i],j]],If[j<7,Part[V[i],j+1],0]]==False,Goto[aa]],{j,0,7}]; m=m+1;Print[m,":"," ",0," ",Part[V[i],1]," ",Part[V[i],2]," ",Part[V[i],3]," ",Part[V[i],4]," ",Part[V[i],5]," ",Part[V[i],6]," ",Part[V[i],7]];Label[aa];Continue,{i,1,7!}]

Extensions

a(10)-a(26) from Max Alekseyev, Sep 17 2013

A072617 Number of essentially different ways of arranging numbers 1 through 2n around a circle so that the sum of each pair of adjacent numbers is prime, with the odd and even numbers in order in opposite directions.

Original entry on oeis.org

1, 1, 1, 1, 1, 2, 1, 1, 1, 0, 0, 2, 1, 1, 2, 0, 0, 1, 1, 1, 3, 0, 0, 1, 0, 0, 2, 1, 1, 2, 0, 0, 2, 1, 1, 1, 0, 0, 3, 0, 0, 1, 0, 0, 3, 0, 0, 3, 1, 1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 5, 0, 0, 3, 0, 0, 4, 1, 1, 4, 0, 0, 2, 1, 1, 2, 0, 0, 2, 0, 0, 4, 0, 0, 5, 0, 0, 4, 1, 1, 5, 0, 0, 3, 1, 1, 2, 1, 1, 4, 0
Offset: 1

Views

Author

T. D. Noe, Jun 25 2002

Keywords

Comments

A very restricted form of the prime circle problem whose sequence is A051252. Finding these solutions is very fast because there are only n possible solutions to try. See A072616 for the case where only the odd numbers or only the even numbers are in order. Note that a(2)=1 because the two solutions are essentially the same. Solutions can be printed by removing comments from the Mathematica program.
There is a provable solution for n when either (a) 2n+1 and 2n+3 are prime, (b) 2k+1, 2k+3, 2k+2n+1 and 2k+2n+3 are prime for some 0 < k < n-1, or (c) 2n-1, 2n+1 and 4n-1 are primes. Part (a) is due to Mike Hennebry. Note that cases (a) and (b) involve 3 sets of twin primes. For n > 3, due to the form of twin primes, it can be shown that (a) implies not (b) and not (c).

Examples

			a(6) = 2 because there are two ways: {1,10,3,8,5,6,7,4,9,2,11,12} and {1,4,3,2,5,12,7,10,9,8,11,6}.
		

Crossrefs

Programs

  • Mathematica
    For[lst={}; n=1, n<=100, n++, oddTable=Append[Table[2i-1, {i, n}], 1]; evenTable=Table[2n+2-2i, {i, n}]; evenTable=Join[evenTable, evenTable]; For[cnt=0; i=1, i<=n, i++, j=0; allPrime=True; While[j
    				

A072618 Numbers n for which the prime circle problem has a simple solution: the arrangement of numbers 1 through 2n around a circle is such that the sum of each pair of adjacent numbers is prime and the odd and even numbers are in order in opposite directions.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 13, 14, 15, 18, 19, 20, 21, 24, 27, 28, 29, 30, 33, 34, 35, 36, 39, 42, 45, 48, 49, 50, 51, 52, 53, 54, 60, 63, 66, 67, 68, 69, 72, 73, 74, 75, 78, 81, 84, 87, 88, 89, 90, 93, 94, 95, 96, 97, 98, 99, 102, 105, 108, 111, 112, 113, 114, 117, 118
Offset: 1

Views

Author

T. D. Noe, Jun 25 2002

Keywords

Comments

A very restricted form of the prime circle problem whose sequence is A051252. This sequence lists the n for which A072617(n) is positive. See A072616 for the case where only the odd numbers or only the even numbers are in order.
There is a provable solution for n when either (a) 2n+1 and 2n+3 are prime, (b) 2k+1, 2k+3, 2k+2n+1 and 2k+2n+3 are prime for some 0 < k < n-1, or (c) 2n-1, 2n+1 and 4n-1 are primes. Part (a) is due to Mike Hennebry. Note that cases (a) and (b) involve 3 sets of twin primes. For n > 3, due to the form of twin primes, it can be shown that (a) implies not (b) and not (c).

Examples

			n=6 is on the list because the simple solution is {1, 10, 3, 8, 5, 6, 7, 4, 9, 2, 11, 12}.
		

Crossrefs

Programs

  • Haskell
    import Data.List (transpose)
    a072618 n = a072618_list !! (n-1)
    a072618_list = filter f [1 ..] where
       f x = any (all ((== 1) . a010051' . fromIntegral)) $
             map cs [concat $ transpose [[2*x, 2*x-2 .. 2] , us] |
                     us <- map (uncurry (++) . (uncurry $ flip (,))
                                . flip splitAt [1, 3 .. 2 * x]) [1 .. x]]
       cs zs = (head zs + last zs) : zipWith (+) zs (tail zs)
    -- Reinhard Zumkeller, Mar 17 2013
  • Mathematica
    For[lst={}; n=1, n<=100, n++, oddTable=Append[Table[2i-1, {i, n}], 1]; evenTable=Table[2n+2-2i, {i, n}]; evenTable=Join[evenTable, evenTable]; For[cnt=0; i=1, i<=n, i++, j=0; allPrime=True; While[j0, AppendTo[lst, n]]]; lst

Extensions

More terms from Robert G. Wilson v, Jun 28 2002

A227050 Number of essentially different ways of arranging numbers 1 through 2n around a circle so that the sum and absolute difference of each pair of adjacent numbers are prime.

Original entry on oeis.org

0, 0, 0, 0, 0, 2, 1, 4, 88, 0, 976, 22277, 22365, 376002, 3172018, 5821944, 10222624, 424452210, 6129894510, 38164752224
Offset: 1

Views

Author

Tim Cieplowski, Jun 29 2013

Keywords

Comments

See a similar problem, but for the set of numbers {0 through (n-1)}. - Stanislav Sykora, May 30 2014

Examples

			For n = 6 the a(6) = 2 solutions are (1, 4, 9, 2, 5, 12, 7, 10, 3, 8, 11, 6) and (1, 6, 11, 8, 3, 10, 7, 4, 9, 2, 5, 12) because abs(1 - 4) = 3 and 1 + 4 = 5 are prime, etc.
		

Crossrefs

Cf. similar sequences: A051252 (with sums of neighbors prime), A242527 (with sums of neighbors prime), A228626 (with differences of neighbors prime), A242528 (with sums and differences of neighbors prime).

Programs

  • Mathematica
    A227050[n_] :=
    Count[Map[lpf, Map[j1f, Permutations[Range[2,2 n]]]], 0]/2;
    j1f[x_] := Join[{1}, x, {1}];
    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[A227050[n], {n, 1, 6}]
    (* OR, a less simple, but more efficient implementation. *)
    A227050[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[]];
          A227050[n, Join[perm, {new}],
           Complement[Range[2 n], perm, {new}]];
          ];
         Return[ct];
         ];
       ];
    Table[ct = 0; A227050[n, {1}, Range[2, 2 n]]/2, {n, 1, 10}]
    (* Robert Price, Oct 22 2018 *)

Extensions

a(15)-a(18) added by Tim Cieplowski, Jan 04 2015
a(19) from Fausto A. C. Cariboni, Jun 06 2017
a(20) from Bert Dobbelaere, Feb 15 2020

A229005 Number of undirected circular permutations i_0, i_1, ..., i_n of 0, 1, ..., n such that all the n+1 numbers |i_0^2-i_1^2|, |i_1^2-i_2^2|, ..., |i_{n-1}^2-i_n^2|, |i_n^2-i_0^2| are of the form (p-1)/2 with p an odd prime.

Original entry on oeis.org

1, 0, 1, 0, 1, 6, 3, 16, 18, 122, 97, 2725, 26457, 10615, 367132, 158738, 1356272, 72423339
Offset: 1

Views

Author

Zhi-Wei Sun, Sep 10 2013

Keywords

Comments

Conjecture: a(n) > 0 except for n = 2, 4.

Examples

			a(1) = 1 due to the circular permutation (0,1).
a(2) = 0 since 2*2^2+1 is composite.
a(3) = 1 due to the circular permutation (0,1,2,3).
a(4) = 0 since 2*(4^2-k^2)+1 is composite for any k = 0,2,3.
a(5) = 1 due to the circular permutation (0,1,4,5,2,3).
a(6) = 6 due to the circular permutations
  (0,1,3,2,5,4,6), (0,1,4,6,5,2,3), (0,1,6,4,5,2,3),
  (0,3,1,2,5,4,6), (0,3,2,1,4,5,6), (0,3,2,5,4,1,6).
a(7) = 3 due to the circular permutations
  (0,1,7,4,6,5,2,3), (0,3,2,1,7,4,5,6), (0,3,2,5,4,7,1,6).
a(8) = 16 due to the circular permutations
  (0,1,3,2,5,8,7,4,6), (0,1,6,4,7,8,5,2,3),
  (0,1,7,8,4,6,5,2,3), (0,1,8,7,4,6,5,2,4),
  (0,3,1,2,5,8,7,4,6), (0,3,2,1,4,7,8,5,6),
  (0,3,2,1,7,4,8,5,6), (0,3,2,1,7,8,4,5,6),
  (0,3,2,1,7,8,5,4,6), (0,3,2,1,8,7,4,5,6),
  (0,3,2,5,4,7,8,1,6), (0,3,2,5,4,8,7,1,6),
  (0,3,2,5,8,1,7,4,6), (0,3,2,5,8,4,7,1,6),
  (0,3,2,5,8,7,1,4,6), (0,3,2,5,8,7,4,1,6).
a(9) > 0 due to the permutation (0,3,2,1,6,4,7,8,5,9).
a(10) > 0  due to the permutation (0,9,5,6,4,7,8,10,2,3,1).
		

Crossrefs

Programs

  • Mathematica
    (* A program to compute required circular permutations for n = 7. To get "undirected" circular permutations, we should identify a circular permutation with the one of the opposite direction; for example, (0,6,1,7,4,5,2,3) is identical to (0,3,2,5,4,7,1,6) if we ignore direction. Thus a(7) is half of the number of circular permutations yielded by this program. *)
    p[i_,j_]:=PrimeQ[2*Abs[i^2-j^2]+1]
    V[i_]:=Part[Permutations[{1,2,3,4,5,6,7}],i]
    m=0
    Do[Do[If[p[If[j==0,0,Part[V[i],j]],If[j<7,Part[V[i],j+1],0]]==False,Goto[aa]],{j,0,7}];m=m+1;Print[m,":"," ",0," ",Part[V[i],1]," ",Part[V[i],2]," ",Part[V[i],3]," ",Part[V[i],4]," ",Part[V[i],5]," ",Part[V[i],6]," ",Part[V[i],7]];Label[aa];Continue,{i,1,7!}]

Extensions

a(10)-a(18) from Alois P. Heinz, Sep 10 2013

A072616 Number of essentially different ways of arranging numbers 1 through 2n around a circle so that the sum of each pair of adjacent numbers is prime and the odd (or even) numbers are in order.

Original entry on oeis.org

1, 1, 1, 1, 4, 8, 2, 5, 18, 2, 9, 100, 80, 224, 567, 200, 225, 2535, 1573, 10890, 132651, 34476, 79768, 319740, 42282, 257337, 3445032, 4274240, 36781568, 260272120
Offset: 1

Views

Author

T. D. Noe, Jun 25 2002

Keywords

Comments

A restricted form of the prime circle problem whose sequence is A051252. Note that a(2)=1 because the two solutions are essentially the same. The number of solutions is the same for odd or even numbers in order because a solution having the odd numbers in order can be converted to a solution having even numbers in order by subtracting 1 from even numbers and adding 1 to odd numbers. For example, {1, 2, 3, 8, 5, 6, 7, 4, 9, 10} becomes {2, 1, 4, 7, 6, 5, 8, 3, 10, 9}. Is the number of solutions always positive? See A072617 for some simple solutions to the prime circle problem.

Examples

			a(5) = 4 because there are four ways: {1,2,3,8,5,6,7,4,9,10}, {1,2,3,8,5,6,7,10,9,4}, {1,4,3,8,5,6,7,10,9,2} and {1,10,3,8,5,6,7,4,9,2}.
		

Crossrefs

Programs

  • Mathematica
    maxN=14; $RecursionLimit=500; try[lev_] := Module[{t, j}, If[lev>2n, (*found a solution*)(*Print[soln]; *) cnt++, (*else append another number to the soln list*) t=soln[[lev-1]]; If[OddQ[lev], (*odd level*) soln[[lev]]=lev; try[lev+1]; soln[[lev]]=0, For[j=1, j<=Length[s[[t]]], j++, (*even level*) If[ !MemberQ[soln, s[[t]][[j]]], soln[[lev]]=s[[t]][[j]]; try[lev+1]; soln[[lev]]=0]]]]]; For[lst={}; n=1, n<=maxN, n++, s=Table[{}, {2n}]; For[i=1, i<=2n, i=i+2, For[j=1, j<=2n, j++, If[i!=j&&PrimeQ[i+j]&&PrimeQ[Mod[i+2, 2n]+j], AppendTo[s[[i]], j]]]]; soln=Table[0, {2n}]; soln[[1]]=1; cnt=0; try[2]; AppendTo[lst, cnt]]; lst
Showing 1-10 of 26 results. Next