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!)
A350404 Number of solutions to +-2 +- 3 +- 5 +- 7 +- ... +- prime(n) = 0 or 1. 4
1, 0, 1, 2, 1, 2, 3, 4, 6, 10, 16, 26, 45, 78, 138, 244, 439, 784, 1417, 2572, 4698, 8682, 16021, 29720, 55146, 102170, 190274, 356804, 671224, 1269022, 2404289, 4521836, 8535117, 16134474, 30635869, 58062404, 110496946, 210500898, 401422210, 767158570, 1467402238 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,4
LINKS
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
Sequence in context: A290973 A173497 A022875 * A325841 A076480 A002730
KEYWORD
nonn
AUTHOR
Ilya Gutkovskiy, Dec 29 2021
EXTENSIONS
a(39)-a(40) from Michael S. Branicky, Jan 16 2022
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 27 11:10 EDT 2024. Contains 372019 sequences. (Running on oeis4.)