cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A064365 a(0) = 0; thereafter a(n) = a(n-1)-prime(n) if positive and new, otherwise a(n) = a(n-1)+prime(n), where prime(n) is the n-th prime.

This page as a plain text file.
%I A064365 #54 May 31 2021 03:26:44
%S A064365 0,2,5,10,3,14,1,18,37,60,31,62,25,66,23,70,17,76,15,82,11,84,163,80,
%T A064365 169,72,173,276,383,274,161,34,165,28,167,316,467,310,147,314,141,320,
%U A064365 139,330,137,334,135,346,123,350,121,354,115,356,105,362,99,368,97,374,93
%N A064365 a(0) = 0; thereafter a(n) = a(n-1)-prime(n) if positive and new, otherwise a(n) = a(n-1)+prime(n), where prime(n) is the n-th prime.
%C A064365 '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).
%C A064365 Does every positive integer appear in the sequence? This seems unlikely, since 4 has not appeared in 70000 terms.
%C A064365 Note: this is similar to _Clark Kimberling_'s A022831, except in the latter sequence the words 'and new' have been omitted.
%C A064365 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
%H A064365 N. J. A. Sloane, <a href="/A064365/b064365.txt">First 70000 terms</a>
%H A064365 <a href="/index/Rea#Recaman">Index entries for sequences related to Recamán's sequence</a>
%F A064365 a(n) = A117128(n) - 1. - _Thomas Ordowski_, Dec 05 2016
%e A064365 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.
%t A064365 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). *)
%o A064365 (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
%o A064365 (Haskell)
%o A064365 import Data.Set (singleton, notMember, insert)
%o A064365 a064365 n = a064365_list !! n
%o A064365 a064365_list = 0 : f 0 a000040_list (singleton 0) where
%o A064365    f x (p:ps) s | x' > 0 && x' `notMember` s = x' : f x' ps (insert x' s)
%o A064365                 | otherwise                  = xp : f xp ps (insert xp s)
%o A064365                 where x' = x - p; xp = x + p
%o A064365 -- _Reinhard Zumkeller_, Apr 26 2012
%o A064365 (Python)
%o A064365 from sympy import primerange, prime
%o A064365 def aupton(terms):
%o A064365   alst = [0]
%o A064365   for n, pn in enumerate(primerange(1, prime(terms)+1), start=1):
%o A064365     x = alst[-1] - pn
%o A064365     alst += [x if x > 0 and x not in alst else alst[-1] + pn]
%o A064365   return alst
%o A064365 print(aupton(60)) # _Michael S. Branicky_, May 30 2021
%Y A064365 Cf. A005132, A022831, A117128.
%K A064365 nonn,easy,nice,look,hear
%O A064365 0,2
%A A064365 _Neil Fernandez_, Sep 25 2001
%E A064365 More terms from _Robert G. Wilson v_, Sep 26 2001
%E A064365 Further terms from _N. J. A. Sloane_, Feb 10 2002
%E A064365 Added initial term a(0)=0, in analogy with A128204, A005132, A053461, A117073/A078783. - _M. F. Hasler_, Mar 07 2012