OFFSET
1,1
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
EXAMPLE
67 is in the sequence because 67 = 7 + 11 + 13 + 17 + 19.
MAPLE
q:= proc(n) local p, q, s; p, q, s:= prevprime(n+1)$3;
do if p=2 then return false
elif s=n then return true
elif s<n then p:= prevprime(p); s:= s+p;
else s:= s-q; q:= prevprime(q)
fi
od
end:
select(q, [$3..150])[]; # Alois P. Heinz, Oct 31 2020
MATHEMATICA
okQ[n_] := Module[{p, q, s}, {p, q, s} = Table[NextPrime[n + 1, -1], {3}]; While[True, Which[
p == 2, Return@ False,
s == n, Return@ True,
s < n, p = NextPrime[p, -1]; s = s + p,
True, s = s - q; q = NextPrime[q, -1]]]];
Select[Range[3, 150], okQ] (* Jean-François Alcover, Feb 21 2022, after Alois P. Heinz *)
PROG
(Python)
from sympy import prevprime
def ok(n):
if n < 2: return False
p, q, s = [prevprime(n+1)] * 3
while True:
if p == 2: return False
if s == n: return True
elif s < n: p = prevprime(p); s += p
else: s -= q; q = prevprime(q)
print([k for k in range(150) if ok(k)]) # Michael S. Branicky, Feb 21 2022 after Alois P. Heinz
CROSSREFS
KEYWORD
nonn
AUTHOR
Ilya Gutkovskiy, Oct 28 2020
STATUS
approved