A125001
Non-insertable primes: primes with property that no matter where you insert (or prepend or append) a digit you get a composite number (except for prepending a zero).
Original entry on oeis.org
369293, 3823867, 5364431, 5409259, 7904521, 8309369, 9387527, 9510341, 22038829, 27195601, 28653263, 38696543, 39091441, 39113161, 43744697, 45095839, 45937109, 48296921, 48694231, 49085093, 49106677, 50791927
Offset: 1
369293 is a member because all of 1369293, 2369293, 3369293, ..., 3069293, 3169293, ..., 3692930, ..., 3692939 are composite.
-
nipQ[x_]:=Module[{id=IntegerDigits[x],len},len=Length[id];AllTrue[ Select[ Flatten[Table[FromDigits[Insert[id,n,i]],{i,len+1},{n,0,9}],1],#!=x&], CompositeQ]]; Select[ Prime[Range[3050000]],nipQ] (* The program uses the AllTrue function from Mathematica version 10 *) (* Harvey P. Dale, Apr 12 2018 *)
-
from sympy import isprime
from itertools import islice
def ok(n):
if not isprime(n): return False
s = str(n)
for c in "0123456789":
for k in range(len(s)+1):
w = s + c if k == 0 else s[:-k] + c + s[-k:]
if w[0] != "0" and isprime(int(w)): return False
return True
print([k for k in range(10**7) if ok(k)]) # Michael S. Branicky, Sep 29 2022
A357436
Start with a(1)=2; to get a(n+1) insert in a(n) the smallest possible digit at the rightmost possible position such that the new number is a prime.
Original entry on oeis.org
2, 23, 223, 2203, 22003, 220013, 2200103, 22000103, 223000103, 2230001003, 22300010023, 223000100023, 2230001000203, 22301001000203, 223010001000203, 2230010001000203, 22300010001000203, 222300010001000203, 2223000100010001203, 22203000100010001203, 222030001000010001203, 2220300010200010001203
Offset: 1
a(2) = 23 because the numbers 20, 21, 12, 22 obtained from a(1) = 2 are composite and 23 is a prime.
For n=6, starting from a(5)=22003 and appending a digit "0" from right to left gives 220030, 220003, 202003, which are not primes. Inserting a digit "1" from right to left gives 220031 which also is not prime, and 220013 which is prime, so a(6) = 220013.
-
f:= proc(n) local x, y,z, j;
for x from 0 to 9 do
for j from 0 to length(n)-`if`(x=0,1,0) do
y:= n mod 10^j;
z:= y + x*10^j + 10*(n-y);
if isprime(z) then return z fi;
od od;
FAIL
end proc:
R:= 2: x:= 2:
for count from 2 to 30 while x <> FAIL do
x:= f(x); R:= R, x;
od:
R; # Robert Israel, Sep 29 2022
-
a[1]=2; a[n_] := a[n] = Catch@ Block[{p, d = IntegerDigits[a[n-1]]}, Do[p = FromDigits@ Insert[d, c, -i]; If[p > a[n - 1] && PrimeQ[p], Throw@p], {c, 0, 9}, {i, 1 + Length@ d}]]; Array[a, 22] (* Giovanni Resta, Oct 13 2022 *)
-
from sympy import isprime
from itertools import islice
def anext(an):
s = str(an)
for c in "0123456789":
for k in range(len(s)+1):
w = s + c if k == 0 else s[:-k] + c + s[-k:]
if w[0] != "0" and isprime(int(w)): return int(w)
def agen(an=2):
while an != None: yield an; an = anext(an)
print(list(islice(agen(), 22))) # Michael S. Branicky, Sep 29 2022
Showing 1-2 of 2 results.
Comments