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.
2, 23, 233, 2333, 23333, 233323, 2333231, 23332301, 233323001, 2333230019, 23332030019, 233320360019, 2333203600159, 23332036001959, 233320360019569, 2333203600195669, 23332036001956469, 233320360019564269, 2333203600195642469, 23332036001956424629, 233320360019564246269
Offset: 1
Examples
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.
Links
- Michael S. Branicky, Table of n, a(n) for n = 1..1000 (terms 1..77 from Bartlomiej Pawlik)
Programs
-
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 *)
-
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
Comments