login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A356557
Start with a(1)=2; to get a(n+1) insert in a(n) at the rightmost possible position the smallest possible digit such that the new number is a prime.
3
2, 23, 233, 2333, 23333, 233323, 2333231, 23332301, 233323001, 2333230019, 23332030019, 233320360019, 2333203600159, 23332036001959, 233320360019569, 2333203600195669, 23332036001956469, 233320360019564269, 2333203600195642469, 23332036001956424629, 233320360019564246269
OFFSET
1,1
COMMENTS
Extending a number by inserting a prepending "0" is obviously not allowed. Rightmostness of position has precedence over smallness of digit. If no prime extension exists, the sequence terminates.
Sequence inspired by A332603.
Sequence construction very similar to A357436 (the difference arises from the order of the conditions).
Length of a(n) is n.
Is the sequence infinite? The analogous sequences using bases 2, 3, 4, 5 and 7 are finite.
Sequence terminates if and only if it contains a term of A125001.
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..1000 (terms 1..77 from Bartlomiej Pawlik)
EXAMPLE
a(2) = 23 because the numbers 20, 21, 22 obtained from a(1) = 2 are composite and 23 is a prime.
For n=6, starting from a(5)=23333 and appending a new rightmost digit gives 233330, 233331, ..., 233339 which are not primes. Inserting a digit second-rightmost gives 233303 and 233313 which are also not prime, and 233323 which is prime, so a(6) = 233323.
MATHEMATICA
k = 2; K = {k}; For[n = 1, n <= 20, n++, r = 0; For[p = IntegerLength[k] + 1, p >= 1, p--, If[r == 1, Break[]]; For[d = 0, d <= 9, d++, If[PrimeQ[ m = ToExpression[StringInsert[ToString[k], ToString[d], p]]], If[k != m, k = m, Print["FINITE"]]; AppendTo[K, k]; r = 1; Break[]]]]]; Print[K] (* Samuel Harkness, Sep 29 2022 *)
PROG
(Python)
from sympy import isprime
from itertools import islice
def anext(an):
s = str(an)
for k in range(len(s)+1):
for c in "0123456789":
w = s + c if k == 0 else s[:-k] + c + s[-k:]
if isprime(int(w)): return int(w)
def agen(an=2):
while an != None: yield an; an = anext(an)
print(list(islice(agen(), 21))) # Michael S. Branicky, Aug 12 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Bartlomiej Pawlik, Aug 12 2022
STATUS
approved