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-2 of 2 results.

A335047 Maximum sum of primes (see Comments).

Original entry on oeis.org

0, 3, 8, 17, 24, 37, 52, 69, 86, 107, 128, 153, 178, 207, 236, 269, 302, 339, 376, 417, 458, 503, 548, 597, 646, 699, 752, 809, 866, 927, 988, 1053, 1118, 1187, 1256, 1329, 1402, 1479, 1556, 1637, 1718, 1803, 1888, 1977, 2066, 2159, 2252, 2349, 2446, 2547, 2648
Offset: 1

Views

Author

Ivan N. Ianakiev, Jun 05 2020

Keywords

Comments

Out of all permutations of the numbers 1..n such that the sum of all adjacent numbers is a prime (A064821) find the one with the maximum sum of the primes. a(n) is the respective maximum sum or equals zero if a permutation does not exist.
The sum of primes arising from a permutation of 1..n is always equal to n*(n+1) minus the values of the two endpoints, so for n > 6 it is probable that a(n) = n*(n+1) - (1+3) if n is odd and a(n) = n*(n+1) - (1+2) if n is even. - Giovanni Resta, Jun 05 2020

Examples

			For n = 4 there are 4 permutations: 1234, 1432, 3214, 3412. The one with the maximum sum of 17 (5+7+5) is 1432.
		

Crossrefs

Programs

  • Mathematica
    p[n_]:=Permutations[Range[n]];f[n_]:=Max[Total/@Select[Table[Table[
    p[n][[j,i]]+p[n][[j,i+1]],{i,1,Length[p[n][[j]]]-1}],{j,1,Length[p[n]]}],
    AllTrue[#,PrimeQ]&]];f/@Range[7] (* slow, just for demo *)
    G[n_] := G[n] = Reap[Do[If[PrimeQ[i + j], Sow[i <-> j]], {i, n}, {j, i-1}]][[2, 1]]; a[n_] := Block[{p = 1 + Boole@ OddQ@ n, ep, s}, ep = SortBy[ Select[ Tuples[ Range[1, n, p], 2], #[[1]] > #[[2]] &], Total]; s = SelectFirst[ ep, FindHamiltonianPath[ G[n], #[[1]], #[[2]]] != {} &, {}]; If[s == {}, 0, n (n + 1) - Total[s]]]; Array[a, 51] (* Giovanni Resta, Jun 05 2020 *)

Extensions

More terms from Giovanni Resta, Jun 05 2020

A335048 Minimum sum of primes (see Comments).

Original entry on oeis.org

0, 3, 8, 13, 22, 31, 44, 57, 74, 91, 112, 133, 158, 183, 212, 241, 274, 307, 344, 381, 422, 463, 508, 553, 602, 651, 704, 757, 814, 871, 932, 993, 1058, 1123, 1192, 1261, 1334, 1407, 1484, 1561, 1642, 1723, 1808, 1893, 1982, 2071, 2164, 2257, 2354, 2451, 2552
Offset: 1

Views

Author

Ivan N. Ianakiev, Jun 05 2020

Keywords

Comments

Out of all permutations of the numbers 1..n such that the sum of all adjacent numbers is a prime (A064821) find the one with the minimum sum of the primes. a(n) is the respective minimum sum or equals zero if a permutation does not exist.
The sum of primes arising from a permutation of 1..n is always equal to n*(n+1) minus the values of the two endpoints, so for n > 1 it is probable that a(n) = n*(n+1) - (n+n-2) if n is odd and a(n) = n*(n+1) - (n+n-1) if n is even. - Giovanni Resta, Jun 05 2020

Examples

			For n = 4 there are 4 permutations: 1234, 1432, 3214, 3412. The one with the minimum sum of 13 (5+3+5) is 3214.
		

Crossrefs

Programs

  • Mathematica
    p[n_]:=Permutations[Range[n]];g[n_]:=Min[Total/@Select[Table[Table[
    p[n][[j,i]]+p[n][[j,i+1]],{i,1,Length[p[n][[j]]]-1}],{j,1,Length[p[n]]}],AllTrue[#,PrimeQ]&]];g/@Range[7] (* slow, just for demo *)
    G[n_] := G[n] = Reap[Do[If[PrimeQ[i + j], Sow[i <-> j]], {i, n}, {j, i-1}]][[2, 1]]; a[n_] := Block[{p = 1 + Boole@OddQ@n, ep, s}, ep = Reverse@ SortBy[ Select[ Tuples[ Range[1, n, p], 2], #[[1]] > #[[2]] &], Total]; s = SelectFirst[ ep, FindHamiltonianPath[G[n], #[[1]], #[[2]]] != {} &, {}]; If[s == {}, 0, n (n + 1) - Total[s]]]; Array[a, 51] (* Giovanni Resta, Jun 05 2020 *)

Extensions

More terms from Giovanni Resta, Jun 05 2020
Showing 1-2 of 2 results.