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.
%I A374965 #47 Oct 20 2024 23:57:05 %S A374965 1,3,4,9,19,12,25,51,103,28,57,115,231,463,46,93,187,375,751,70,141, %T A374965 283,82,165,331,100,201,403,807,1615,3231,6463,12927,25855,51711, %U A374965 103423,156,313,166,333,667,1335,2671,192,385,771,1543,222,445,891,1783,238,477 %N A374965 a(n) = 2*a(n-1) + 1 for a(n-1) not prime, otherwise a(n) = prime(n) - 1; with a(1)=1. %C A374965 Sequence is clearly infinite and not monotonic. Primes are sparse. %C A374965 When is the next prime after n=10016 ? [Answer from _N. J. A. Sloane_, Aug 01 2024: The point of Bill's question is that a(10016) is the prime 838951, which is in fact the 289th prime in this sequence, as can be seen from A375028 and A373799. Thanks to the work of Lucas A. Brown (see A050412), we now know that the answer to Bill's question is that the 290th prime is the 102410-digit prime 104917*2^340181 - 1 = 5079...8783, which is a(350198). It was a very good question!] %C A374965 It appears that the trajectories for different initial conditions a(1) converge to a few attractors. For all prime values and most nonprime values of a(1), the trajectories converge to the same attractor with prime 838951 at n=10016. For a(1) = 147, 295, 591, 1183, ... the trajectories converge to prime 85796863 at n=4390. For a(1) = 658, the trajectory reaches a prime with 240983 digits after 800516 steps. For a(1) = 509202, the trajectory never reaches a prime (see A050412, A052333). - _Chai Wah Wu_, Jul 29 2024 %H A374965 Harvey P. Dale, <a href="/A374965/b374965.txt">Table of n, a(n) for n = 1..1000</a> %H A374965 N. J. A. Sloane, <a href="https://www.youtube.com/watch?v=3RAYoaKMckM">A Nasty Surprise in a Sequence and Other OEIS Stories</a>, Experimental Mathematics Seminar, Rutgers University, Oct 10 2024, Youtube video; <a href="https://sites.math.rutgers.edu/~zeilberg/expmath/sloane85BD.pdf">Slides</a> [Mentions this sequence] %e A374965 a(1) = 1 is not a prime, so a(2) = 2*1+1 = 3. a(2) is a prime, so a(3) = prime(3)-1 = 4. a(4) = 2*4+1 = 9. %t A374965 a[n_] := a[n] = If[!PrimeQ[a[n-1]], 2*a[n-1] + 1, Prime[n]-1]; a[1] = 1; Array[a, 60] (* _Amiram Eldar_, Jul 25 2024 *) %t A374965 nxt[{n_,a_}]:={n+1,If[!PrimeQ[a],2a+1,Prime[n+1]-1]}; NestList[nxt,{1,1},60][[;;,2]] (* _Harvey P. Dale_, Jul 28 2024 *) %o A374965 (Python) %o A374965 from itertools import islice %o A374965 from sympy import isprime, nextprime %o A374965 def A374965_gen(): # generator of terms %o A374965 a, p = 1, 3 %o A374965 while True: %o A374965 yield a %o A374965 a, p = p-1 if isprime(a) else (a<<1)+1, nextprime(p) %o A374965 A374965_list = list(islice(A374965_gen(),30)) # _Chai Wah Wu_, Jul 29 2024 %Y A374965 The primes are listed in A375028 (see also A373798 and A373804). %Y A374965 Cf. A050412 and A052333. %K A374965 nonn,easy %O A374965 1,2 %A A374965 _Bill McEachen_, Jul 25 2024