login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(n) = smallest k such that n can be expressed as a signed sum of the first k primes.
5

%I #37 May 30 2023 07:43:55

%S 3,2,1,4,3,2,3,4,5,6,3,4,5,4,5,6,7,4,5,6,7,6,5,6,5,6,7,6,5,8,7,6,7,8,

%T 7,6,7,6,7,8,7,6,7,8,7,8,9,8,7,8,9,8,7,8,7,8,9,8,7,8,9,8,9,8,9,10,9,8,

%U 9,10,9,8,9,8,9,10,9,8,9,10,9,10,9,10,9,10

%N a(n) = smallest k such that n can be expressed as a signed sum of the first k primes.

%C Smallest k such that n = +- p_1 +- p_2 +- p_3 +- ... +- p_k for a suitable choice of signs, where p_i = i-th prime.

%D Allan C. Wechsler, Posting to Sequence Fans Mailing List, circa Aug 29 2019.

%H Seiichi Manyama, <a href="/A327467/b327467.txt">Table of n, a(n) for n = 0..10000</a> (terms 0..1000 from Giovanni Resta)

%H Karl-Heinz Hofmann, <a href="/A327467/a327467.txt">Examples for n = 0 to 778</a>

%H Karl-Heinz Hofmann, <a href="/A327467/a327467.png">Visualization of the conjecture of _Kei Fujimoto_ (see formula)</a>

%F a(A007504(n)) = n for n > 0. - _Seiichi Manyama_, Sep 30 2019

%F Conjecture. Let k be the smallest integer satisfying n<=A007504(k). If n=9 or 16, a(n)=k+3 (so a(9)=6, a(16)=7), else if A007504(k)-n is odd, a(n)=k+1. If A007504(k)-n=2 or 8 or 12, a(n)=k+2, otherwise a(n)=k. - _Kei Fujimoto_, Sep 24 2021

%e Illustration of initial terms:

%e 0 = 2 + 3 - 5

%e 1 = - 2 + 3

%e 2 = 2

%e 3 = - 2 + 3 - 5 + 7

%e 4 = 2 - 3 + 5

%e 5 = 2 + 3

%e 6 = - 2 + 3 + 5

%e 7 = 2 + 3 - 5 + 7

%e 8 = 2 - 3 + 5 - 7 + 11

%e 9 = 2 - 3 + 5 + 7 + 11 - 13

%e 10 = 2 + 3 + 5

%e (for more examples see links)

%t (* 1001 terms *) sgn[w_] := Union@ Abs[Total /@ (w # & /@ Tuples[{1, -1}, Length@w])]; set[n_] := Block[{h = Floor[n/2], p = Prime@ Range@ n, x, y}, x = sgn[Take[p, h]]; y = sgn[Take[p, h - n]]; Union@ Flatten@ Table[{e + f, Abs[e - f]}, {e, x}, {f, y}]]; T = {}; L = 0 Range[1001]; k = 0; While[Length[T] < 1001, k++; s = Select[set[k], # <= 1000 && ! MemberQ[T, #] &]; Do[L[[e + 1]] = k, {e, s}]; T = Union[T, s]]; L (* _Giovanni Resta_, Sep 30 2019 *)

%o (Python)

%o from sympy import sieve as prime

%o def A327467(n):

%o array, np, k = [2], 1, 1

%o while n not in array:

%o temp = []; np += 1; k += 1

%o for item in array:

%o temp.append(item + prime[k])

%o temp.append(abs(item - prime[k]))

%o array = set(temp)

%o return np

%o print([A327467(n) for n in range(0, 100)]) # _Karl-Heinz Hofmann_, May 30 2023

%Y Cf. A007504, A140358.

%K nonn

%O 0,1

%A _N. J. A. Sloane_, Sep 29 2019

%E More terms from _Giovanni Resta_, Sep 30 2019