OFFSET
0,4
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..2000
EXAMPLE
a(6) = 3: 2 + 3 + 5 - 7 + 11 - 13 =
-2 + 3 + 5 - 7 - 11 + 13 =
-2 + 3 - 5 + 7 + 11 - 13 = 1.
MAPLE
s:= proc(n) s(n):= `if`(n<1, 0, ithprime(n)+s(n-1)) end:
b:= proc(n, i) option remember; `if`(n>s(i), 0, `if`(i=0, 1,
b(n+ithprime(i), i-1)+b(abs(n-ithprime(i)), i-1)))
end:
a:=n-> b(0, n)+b(1, n):
seq(a(n), n=0..45); # Alois P. Heinz, Jan 16 2022
MATHEMATICA
s[n_] := s[n] = If[n < 1, 0, Prime[n] + s[n - 1]];
b[n_, i_] := b[n, i] = If[n > s[i], 0, If[i == 0, 1,
b[n + Prime[i], i - 1] + b[Abs[n - Prime[i]], i - 1]]];
a[n_] := b[0, n] + b[1, n];
Table[a[n], {n, 0, 45}] (* Jean-François Alcover, Mar 01 2022, after Alois P. Heinz *)
PROG
(Python)
from itertools import product
from sympy import prime, primerange
def a(n):
if n == 0: return 1
nn = ["0"] + [str(i) for i in primerange(2, prime(n)+1)]
return sum(eval("".join([*sum(zip(nn, ops+("", )), ())])) in {0, 1} for ops in product("+-", repeat=n))
print([a(n) for n in range(18)]) # Michael S. Branicky, Jan 16 2022
(Python)
from sympy import sieve, primerange
from functools import cache
@cache
def b(n, i):
maxsum = 0 if i == 0 else sum(p for p in primerange(2, sieve[i]+1))
if n > maxsum: return 0
if i == 0: return 1
return b(n+sieve[i], i-1) + b(abs(n-sieve[i]), i-1)
def a(n): return b(0, n) + b(1, n)
print([a(n) for n in range(43)]) # Michael S. Branicky, Jan 16 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Ilya Gutkovskiy, Dec 29 2021
EXTENSIONS
a(39)-a(40) from Michael S. Branicky, Jan 16 2022
STATUS
approved