
EXAMPLE

a(0)=53 because 53 is the smallest prime such that all numbers obtained by adding a digit to the right are composite.
a(1)=53 because 5 and 53 are primes.
a(2)=317 because 3, 31, 317 are all primes, and 317 has the same property as 53 when adding a digit to the right.


PROG

(PARI) a(n) = {n++; v = vector(n); i = 1; ok = 0; until (ok, while ((i>1) && (v[i] == 9), v[i] = 0; i); if (i == 1, v[i] = nextprime(v[i]+1), v[i] = v[i]+1); curp = sum (j=1, i, v[j]*(10^(ij))); if (isprime(curp), if (i != n, i++, nbp = 0; for (z=1, 9, if (isprime(10*curp+z), nbp++); ); if (nbp == 0, ok = 1); ); ); ); sum (j=1, n, v[j]*(10^(nj))); }
(Python)
from sympy import isprime, nextprime
def a(n):
p, oo = 2, float('inf')
while True:
extends, reach, r1 = 0, [str(p)], []
while len(reach) > 0 and extends <= n:
minnotext = oo
for s in reach:
wasextended = False
for d in "1379":
if isprime(int(s+d)): r1.append(s+d); wasextended = True
if not wasextended: minnotext = min(minnotext, int(s))
if extends == n and minnotext < oo: return minnotext
if len(r1) > 0: extends += 1
reach, r1 = r1, []
p = nextprime(p)
for n in range(12): print(a(n), end=", ") # Michael S. Branicky, Aug 08 2021
