A374965 a(n) = 2*a(n-1) + 1 for a(n-1) not prime, otherwise a(n) = prime(n) - 1; with a(1)=1.
1, 3, 4, 9, 19, 12, 25, 51, 103, 28, 57, 115, 231, 463, 46, 93, 187, 375, 751, 70, 141, 283, 82, 165, 331, 100, 201, 403, 807, 1615, 3231, 6463, 12927, 25855, 51711, 103423, 156, 313, 166, 333, 667, 1335, 2671, 192, 385, 771, 1543, 222, 445, 891, 1783, 238, 477
Offset: 1
Examples
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.
Links
- Harvey P. Dale, Table of n, a(n) for n = 1..1000
- N. J. A. Sloane, A Nasty Surprise in a Sequence and Other OEIS Stories, Experimental Mathematics Seminar, Rutgers University, Oct 10 2024, Youtube video; Slides [Mentions this sequence]
Programs
-
Mathematica
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 *) 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 *)
-
Python
from itertools import islice from sympy import isprime, nextprime def A374965_gen(): # generator of terms a, p = 1, 3 while True: yield a a, p = p-1 if isprime(a) else (a<<1)+1, nextprime(p) A374965_list = list(islice(A374965_gen(),30)) # Chai Wah Wu, Jul 29 2024
Comments