login
a(1) = 1. If a(n) is prime, a(n+1) = 2*a(n) + 1. If a(n) is not prime, a(n+1) = least prime not already in the sequence.
0

%I #13 Nov 21 2021 09:20:36

%S 1,2,5,11,23,47,95,3,7,15,13,27,17,35,19,39,29,59,119,31,63,37,75,41,

%T 83,167,335,43,87,53,107,215,61,123,67,135,71,143,73,147,79,159,89,

%U 179,359,719,1439,2879,5759,97,195,101,203,103,207,109,219,113,227,455

%N a(1) = 1. If a(n) is prime, a(n+1) = 2*a(n) + 1. If a(n) is not prime, a(n+1) = least prime not already in the sequence.

%C The sequence exhibits consecutive terms of "nearly doubled primes", namely Cunningham Chains (of the first kind), the first of which is 2,5,11,23,47. Each prime in such a chain, except for the last is a term in A005384, and each prime except the first is a term in A005385. Every chain is terminated by composite number m = 2*q + 1, where q is the last prime in the chain. At this point the sequence resets to the smallest prime which has not yet been seen, from which the next chain is propagated, and so on. Since by definition every prime appears, so does every possible Cunningham chain. A similar (companion) sequence can be defined using a(n+1) = 2*a(n) - 1 for a(n) a prime term.

%H Chris K. Caldwell, <a href="https://primes.utm.edu/glossary/page.php?sort=CunninghamChain">Cunningham Chain</a> (PrimePages, Prime Glossary).

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Cunningham_chain">Cunningham chain</a>.

%e a(1) = 1 is not prime, so a(2) = 2, the smallest prime not seen so far. Then a(3) = 2*2 + 1 = 5, a(4) = 2*5 + 1 = 11, and so on, generating the chain 2,5,11,23,47.

%e 47 is not a term in A005384 since 2*47 + 1 = 95 is not prime, after which the sequence resets to 3, the least unused prime so far, from which the next chain 3,7,15 arises, and so on.

%e As an irregular table (each row after the first beginning with a prime and ending with a nonprime), the sequence begins:

%e 1;

%e 2, 5, 11, 23, 47, 95;

%e 3, 7, 15;

%e 13, 27;

%e 17, 35;

%e 19, 39;

%e 29, 59, 119;

%e 31, 63;

%e 37, 75;

%e 41, 83, 167, 335;

%e 43, 87; ...

%t a[1]=1;a[n_]:=a[n]=If[PrimeQ@a[n-1],2a[n-1]+1,k=2;While[MemberQ[Array[a,n-1],k],k=NextPrime@k];k];Array[a,60] (* _Giorgos Kalogeropoulos_, Nov 02 2021 *)

%o (Python)

%o from sympy import isprime, nextprime

%o def aupton(terms):

%o alst, aset = [1], {1}

%o while len(alst) < terms:

%o if isprime(alst[-1]):

%o an = 2*alst[-1] + 1

%o else:

%o p = 2

%o while p in aset: p = nextprime(p)

%o an = p

%o alst.append(an); aset.add(an)

%o return alst

%o print(aupton(60)) # _Michael S. Branicky_, Nov 02 2021

%Y Cf. A000040, A005384, A338945, A075712.

%K nonn,tabf

%O 1,2

%A _David James Sycamore_, Nov 01 2021