OFFSET
1,1
COMMENTS
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
FORMULA
From Michael S. Branicky, Oct 22 2025: (Start)
a(n) = 1 + a(A389929(n)) for n composite, in particular
a(n) = 1 when A389929(n) = 0. (End)
PROG
(Python)
from gmpy2 import is_prime
from functools import cache
def f(n, avoid):
s = str(n)
D = set(p for i in range(len(s)) if len(t:=s[:i]+s[i+1:]) and is_prime(p:=int(t)))
if D and (Dcands:=D-avoid):
return min(Dcands)
A = set(p for i in range(len(s)+1) for d in "0123456789" if is_prime(p:=int(s[:i]+d+s[i:])))
return min(Acands) if A and (Acands:=A-avoid) else 0
@cache
def a(n):
if n > 1 and not is_prime(n):
fn = f(n, set())
return 1 if (fn:=f(n, set())) == 0 else 1 + a(fn)
an, aset = n, {n}
while an != 0:
aset.add(an)
an = f(an, aset)
return len(aset)
# Michael S. Branicky, Oct 22 2025
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Scott R. Shannon, Oct 19 2025
STATUS
approved
