OFFSET
0,2
COMMENTS
'Recamán transform' (see A005132) of the prime sequence. Note that the definition permits repeated terms [though only by addition] (and there are many repeated terms, just as there are in A005132).
Does every positive integer appear in the sequence? This seems unlikely, since 4 has not appeared in 70000 terms.
Note: this is similar to Clark Kimberling's A022831, except in the latter sequence the words 'and new' have been omitted.
The smallest numbers not occurring in the first million terms: 4, 6, 7, 12, 13, 16, 19, 20, 21, 22, 24, 26, 27, 29, 30, 32, 36, 39, 41, 42. - Reinhard Zumkeller, Apr 26 2012
LINKS
FORMULA
a(n) = A117128(n) - 1. - Thomas Ordowski, Dec 05 2016
EXAMPLE
To find a(9) we try subtracting the 9th prime, which is 23, from a(8), which is 37. 37 - 23 = 14, but 14 is already in the sequence (it is a(5)), so we must add. a(9) = 37 + 23 = 60.
MATHEMATICA
a = {0}; Do[ If[ a[ [ -1 ] ] - Prime[ n ] > 0 && Position[ a, a[ [ -1 ] ] - Prime[ n ] ] == {}, a = Append[ a, a[ [ -1 ] ] - Prime[ n ] ], a = Append[ a, a[ [ -1 ] ] + Prime[ n ] ] ], {n, 1, 70} ]; a (* Modified by Ivan N. Ianakiev, Aug 05 2019, to accommodate the new initial term of a(0). *)
PROG
(PARI) A064365(N, s/*=1 to print all terms*/)={ my(a=0, u=0); N & forprime(p=1, prime(N), s & print1(a", "); u=bitor(u, 2^a+=if(a<=p || bittest(u, a-p), p, -p))); a} \\ M. F. Hasler, Mar 07 2012
(Haskell)
import Data.Set (singleton, notMember, insert)
a064365 n = a064365_list !! n
a064365_list = 0 : f 0 a000040_list (singleton 0) where
f x (p:ps) s | x' > 0 && x' `notMember` s = x' : f x' ps (insert x' s)
| otherwise = xp : f xp ps (insert xp s)
where x' = x - p; xp = x + p
-- Reinhard Zumkeller, Apr 26 2012
(Python)
from sympy import primerange, prime
def aupton(terms):
alst = [0]
for n, pn in enumerate(primerange(1, prime(terms)+1), start=1):
x = alst[-1] - pn
alst += [x if x > 0 and x not in alst else alst[-1] + pn]
return alst
print(aupton(60)) # Michael S. Branicky, May 30 2021
CROSSREFS
AUTHOR
Neil Fernandez, Sep 25 2001
EXTENSIONS
More terms from Robert G. Wilson v, Sep 26 2001
Further terms from N. J. A. Sloane, Feb 10 2002
STATUS
approved