login
A389720
a(n) is the largest prime number obtainable by inserting a single digit anywhere in n (including at the beginning or end), or -1 if no such prime is obtainable.
11
7, 71, 29, 83, 47, 59, 67, 97, 89, 97, 109, 911, 127, 613, 149, 157, 167, 617, 181, 919, -1, 821, 229, 823, 241, 257, 269, 827, 283, 929, 307, 631, -1, 733, 349, 359, 367, 937, 389, 839, 409, 941, 421, 743, 449, 457, 467, 947, 487, 499, 509, 751, 523, 953, 547
OFFSET
0,1
COMMENTS
We allow prepending by zero, so the fixed points here are given by A125001.
The indices of the -1 terms are a subsequence of A124665, with the first difference arising from A124665(114) = 891 and a(891) = 8971.
LINKS
EXAMPLE
a(1) = 71 since it is the largest of the primes 11, 13, 17, 19, 31, 41, 61, 71 obtainable by prepending or appending a single digit.
a(69) = 769 since it is the largest of the primes 269, 569, 619, 659, 691, 769 obtainable by prepending, inserting, or appending a single digit.
MAPLE
f:= proc(n) local i, a, b, d, x, m;
m:= -infinity;
for i from 0 to 1+ilog10(n) do
b:= n mod 10^i;
a:= (n-b)/10^i;
for d from 9 by -1 to `if`(a=0, 1, 0) do
x:= (10*a+d)*10^i + b;
if x <= m then break fi;
if isprime(x) then m:= x; break fi;
od
od;
subs(-infinity=-1, m)
end proc:
f(0):= 7:
map(f, [$0..100]); # Robert Israel, Oct 12 2025
PROG
(Python)
from sympy import isprime
def a(n):
s = str(n)
return max((p for i in range(len(s)+1) for d in "0123456789" if isprime(p:=int(s[:i]+d+s[i:]))), default=-1)
print([a(n) for n in range(55)])
KEYWORD
sign,base
AUTHOR
Michael S. Branicky, Oct 12 2025
STATUS
approved