OFFSET
0,3
FORMULA
a(0)=0, a(1)=1, a(n) = a(n-1) + a(n-2) + p(n), where p(n) = min{p:p is prime and |p-n| is minimized, and the smaller prime when n is equidistant between primes}.
EXAMPLE
a(2) = 3 since a(1) + a(0) = 1 and p(2) = 2. Furthermore a(3) = 3 + 1 + p(3) = 7.
MATHEMATICA
p[n_] := (np = NextPrime[n]; pp = Prime[PrimePi[np] - 1];
Which[np > 2 n - pp, pp, np < 2 n - pp, np, True, pp]); (* Using the already existing code from A051697 *)
sequenceLength = 50; (* Specify the desired length of the sequence *)
sequence = {0, 1}; (* Initialize the sequence with the first two terms *)
For[n = 2, n < sequenceLength, n++,
nextTerm = sequence[[-2]] + sequence[[-1]] + p[n];
sequence = Append[sequence, nextTerm]]
Print[sequence]
CROSSREFS
KEYWORD
nonn
AUTHOR
Yanick Willert, Jun 16 2023
STATUS
approved