login
A390019
Smallest prime number != n obtained by removing or adding a single digit anywhere in n, or 0 if no such prime exists.
2
2, 11, 23, 13, 41, 53, 61, 17, 83, 19, 101, 101, 2, 3, 149, 5, 163, 7, 181, 109, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 401, 241, 2, 3, 443, 5, 461, 7, 487, 149, 5, 5, 2, 3, 5, 5, 5, 5, 5, 5, 601, 461, 2, 3, 641, 5, 661, 7, 683, 269, 7, 7, 2, 3, 7, 5
OFFSET
0,1
COMMENTS
Digits can be prepended or appended. Any leading 0 digits upon prepending or removal of the first digit are discarded.
The condition a(n) != n is the same as disallowing prepending by zero in A389929. First differs from A389929 at a(2) = 23 != 2 = A389929(2).
a(9387527) = 0 is the first prime p with a(p) = 0.
LINKS
FORMULA
a(p) > p or 0 for p in A125001.
EXAMPLE
a(2) = 23 since deletiing and prepending cannot produce a prime and 21 and 22 are composite.
PROG
(Python)
from gmpy2 import is_prime
def a(n):
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: return min(D)
A = set(p for i in range(len(s)+1) for d in "0123456789" if not (i==0 and d=='0') and is_prime(p:=int(s[:i]+d+s[i:])))
return min(A, default=0)
print([a(n) for n in range(76)])
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Michael S. Branicky, Oct 22 2025
STATUS
approved