OFFSET
1,1
EXAMPLE
a(4) = 5 because 5, 2*5 + 1 = 11, 2*11 + 1 = 23, 2*23 + 1 = 47 is a sequence of primes of length 4 while 2*47 - 1 = 93 and 2*47 + 1 = 95 are not primes, and 5 is the smallest prime that works.
MAPLE
M:= 10: # for a(1) .. a(N)
f:= proc(n) option remember; local x;
if n mod 3 = 1 then x:= 2*n-1 else x:= 2*n+1 fi;
if isprime(x) then 1 + procname(x) else 1 fi;
end proc:
f(2):= 6: f(3):= 5:
V:= Vector(M):
p:= 1: count:= 0:
for k from 1 while count < M do
p:= nextprime(p);
v:= f(p);
if v <= M and V[v] = 0 then V[v]:= p; count:= count+1; fi
od:
convert(V, list);
PROG
(Python)
from sympy import isprime, nextprime
def A364091(n):
if 5 <= n <= 6: return 8-n
q = 5
while True:
p, c = q, 1
while isprime(p:=(p<<1)+(-1 if p%3==1 else 1)):
c += 1
if c > n:
break
if c == n:
return q
q = nextprime(q) # Chai Wah Wu, Jul 07 2023
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Robert Israel, Jul 04 2023
STATUS
approved