| Displaying 1-9 of 9 results found.
page
1
Weakly primes ( A050249) that are also non-insertable primes ( A125001).
+20
0
34101693667, 40144044691, 45031673353, 58058453543, 89797181359, 95815971907, 106071536707, 171199263119, 181504380313
EXAMPLE
34101693667 is in the list because changing one digit anywhere in another gives a composite number and prepending, inserting or appending any digit (not prepending 0) gives also a composite number.
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.
+10
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
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.
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:
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)])
Deletable primes ( A080608) under the stricter rule that leading zeros are disallowed.
+10
5
2, 3, 5, 7, 13, 17, 23, 29, 31, 37, 43, 47, 53, 59, 67, 71, 73, 79, 83, 97, 103, 107, 113, 127, 131, 137, 139, 157, 163, 167, 173, 179, 193, 197, 223, 229, 233, 239, 263, 269, 271, 283, 293, 307, 311, 313, 317, 331, 337, 347, 353, 359, 367, 373, 379, 383, 397, 431, 433, 439
COMMENTS
Subset of A080608. Numbers 2003, 2017, 2053, 3023, ... are in A080608 but not here.
If you start from a one-digit prime, you can try to build larger and larger deletable primes by inserting digits. If at one point you get stuck and cannot enlarge the number, you have reached a non-insertable prime ( A125001). - Jeppe Stig Nielsen, Mar 28 2021
EXAMPLE
2003 is not a member since removing a digit will either give 003 which has a leading zero, or give one of the numbers 203 or 200 which are both composite. However, 2003 is in A080608 because all of 2003, 003, 03, 3 are prime.
MATHEMATICA
Rest@ Union@ Nest[Function[{a, p}, Append[a, With[{w = IntegerDigits[p]}, If[# == True, p, 0] &@ AnyTrue[Array[If[First@ # == 0, 1, FromDigits@ #] &@ Delete[w, #] &, Length@ w], ! FreeQ[a, #] &]]]] @@ {#, Prime[Length@ # + 1]} &, Prime@ Range@ PrimePi@ 10, 81] (* Michael De Vlieger, Aug 02 2018 *)
PROG
(PARI) is(n) = !ispseudoprime(n)&&return(0); my(d=digits(n)); #d==1&&return(1); for(i=1, #d, my(v=vecextract(d, Str("^"i))); v[1]!=0&&is(fromdigits(v))&&return(1)); 0
(Python)
from sympy import isprime
def ok(n):
if not isprime(n): return False
if n < 10: return True
s = str(n)
si = (s[:i]+s[i+1:] for i in range(len(s)))
return any(t[0] != '0' and ok(int(t)) for t in si)
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.
+10
5
2, 23, 233, 2333, 23333, 233323, 2333231, 23332301, 233323001, 2333230019, 23332030019, 233320360019, 2333203600159, 23332036001959, 233320360019569, 2333203600195669, 23332036001956469, 233320360019564269, 2333203600195642469, 23332036001956424629, 233320360019564246269
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 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.
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)
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.
+10
5
2, 23, 223, 2203, 22003, 220013, 2200103, 22000103, 223000103, 2230001003, 22300010023, 223000100023, 2230001000203, 22301001000203, 223010001000203, 2230010001000203, 22300010001000203, 222300010001000203, 2223000100010001203, 22203000100010001203, 222030001000010001203, 2220300010200010001203
COMMENTS
Extending a number by inserting a prepending "0" is obviously not allowed. Smallness of digit has precedence over rightmostness of position. If no prime extension exists, the sequence terminates.
Sequence construction very similar to A356557 (the difference arises from the order of the conditions).
Length of a(n) is n.
Is the sequence infinite?
Sequence terminates if and only if it contains a term of A125001.
EXAMPLE
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.
MAPLE
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:
MATHEMATICA
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 *)
PROG
(Python)
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)
Smallest prime number != n obtained by removing or adding a single digit anywhere in n, or 0 if no such prime exists.
+10
2
2, 11, 23, 13, 41, 53, 61, 17, 83, 19, 101, 101, 2, 3, 149, 5, 163, 7, 181, 109, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 401, 241, 2, 3, 443, 5, 461, 7, 487, 149, 5, 5, 2, 3, 5, 5, 5, 5, 5, 5, 601, 461, 2, 3, 641, 5, 661, 7, 683, 269, 7, 7, 2, 3, 7, 5
COMMENTS
Digits can be prepended or appended. Any leading 0 digits upon prepending or removal of the first digit are discarded.
The condition a(n) != n is the same as disallowing prepending by zero in A389929. First differs from A389929 at a(2) = 23 != 2 = A389929(2).
a(9387527) = 0 is the first prime p with a(p) = 0.
EXAMPLE
a(2) = 23 since deletiing and prepending cannot produce a prime and 21 and 22 are composite.
PROG
(Python)
from gmpy2 import is_prime
def a(n):
s = str(n)
D = set(p for i in range(len(s)) if len(t:=s[:i]+s[i+1:]) and is_prime(p:=int(t)))
if D: return min(D)
A = set(p for i in range(len(s)+1) for d in "0123456789" if not (i==0 and d=='0') and is_prime(p:=int(s[:i]+d+s[i:])))
return min(A, default=0)
print([a(n) for n in range(76)])
a(n) is the number of distinct primes obtainable by inserting exactly one decimal digit into the decimal representation of prime(n) (at any position, including before the first digit or after the last), with the resulting number required to have no leading zero.
+10
2
2, 8, 2, 8, 10, 10, 10, 12, 8, 6, 7, 10, 10, 7, 8, 8, 7, 10, 9, 7, 7, 8, 9, 5, 10, 15, 10, 6, 15, 12, 11, 12, 9, 5, 11, 10, 7, 8, 12, 9, 10, 10, 8, 10, 11, 10, 12, 9, 10, 12, 8, 10, 8, 8, 9, 8, 10, 12, 10, 9, 11, 10, 9, 11, 5, 9, 10, 10, 9, 8, 8, 8, 14, 8, 9, 8
EXAMPLE
The a(10) = 6 primes obtainable from prime(10) = 29 are 229, 239, 269, 293, 829 and 929.
MAPLE
A392156 := proc(n) local i, j, k, l, p; p := ListTools:-Reverse(convert(ithprime(n), 'base', 10)); k := nops(p); l := []; for i from 0 to 9 do for j from 0 to k do if i + j > 0 then l := [op(l), [op(p[1 .. j]), i, op(p[j + 1 .. k])]]; end if; end do; end do; nops(convert(select(isprime, {op(map(z -> foldl((x, y) -> 10*x + y, 0, op(z)), l))}), set)); end proc: seq( A392156(n), n = 1 .. 76);
PROG
(Python)
from sympy import isprime, prime
def a(n):
s = str(prime(n))
return len(set(p for i in range(len(s)+1) for d in "0123456789"[int(i==0):] if isprime(p:=int(s[:i]+d+s[i:]))))
Start with a(1) = 2; to get a(n+1) insert in a(n) at the leftmost possible position the smallest possible digit such that the new number is a prime.
+10
2
2, 23, 223, 1223, 31223, 231223, 6231223, 61231223, 661231223, 5661231223, 56161231223, 526161231223, 5216161231223, 25216161231223, 425216161231223, 6425216161231223, 66425216161231223, 664325216161231223, 9664325216161231223, 29664325216161231223, 296764325216161231223, 2996764325216161231223
COMMENTS
This is the left-right counterpart of A356557. It uses the same precedence of the insertion position over smallness of the inserted digit, but considers positions from left to right instead of from right to left.
Together with A356557, A357436, and A397084, this sequence belongs to the family obtained by choosing the precedence between digit smallness and insertion position, and the direction in which insertion positions are considered.
Leftmostness of the insertion position has precedence over smallness of the inserted digit.
Prepending a digit 0 is not allowed.
If no prime extension exists, the sequence terminates.
The number a(n) has n decimal digits.
The sequence terminates if and only if it contains a term of A125001.
Is the sequence infinite?
EXAMPLE
a(3) = 223. Starting from 23, the leftmost position is checked first. Prepending 1 gives 123, which is composite, while prepending 2 gives the prime 223.
a(8) = 61231223. Starting from 6231223, no prepended digit produces a prime. At the second insertion position, inserting 1 gives the prime 61231223.
MATHEMATICA
a[1]=2; a[n_]:=a[n]=Catch@Module[{digits=IntegerDigits[a[n - 1]], candidate},
Do[If[position == 1 && digit == 0, Continue[]]; candidate = FromDigits@Insert[digits, digit, position]; If[PrimeQ[candidate], Throw[candidate]], {position, 1, Length[digits] + 1}, {digit, 0, 9}]]; Array[a, 22]
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"[int(k==0):]:
w = s[:k] + c + s[k:]
if isprime(int(w)): return int(w)
def agen(an=2):
while an != None: yield an; an = anext(an)
CROSSREFS
Cf. A356557, the right-to-left counterpart, in which the insertion position also has precedence over smallness of the inserted digit.
Cf. A397084, which also considers insertion positions from left to right, but gives precedence to smallness of the inserted digit over leftmostness of position.
Cf. A357436, in which smallness of the inserted digit has precedence and insertion positions are considered from right to left.
Start with a(1) = 2; to get a(n+1) insert in a(n) the smallest possible digit at the leftmost possible position such that the new number is a prime.
+10
2
2, 23, 223, 2203, 22003, 220013, 2200013, 20200013, 202002013, 2032002013, 20032002013, 200302002013, 2003020020013, 20030200020013, 200302000201013, 2003020002001013, 20030200020001013, 202030200020001013, 2021030200020001013, 20210530200020001013, 202100530200020001013, 2002100530200020001013
COMMENTS
This is the left-right counterpart of A357436. It uses the same precedence of smallness of the inserted digit over the insertion position, but considers positions from left to right instead of from right to left.
Together with A356557, A357436, and A397083, this sequence belongs to the family obtained by choosing the precedence between digit smallness and insertion position, and the direction in which insertion positions are considered.
Smallness of the inserted digit has precedence over leftmostness of its position.
Prepending a 0 is not allowed.
If no prime extension exists, the sequence terminates.
a(n) has n decimal digits.
The sequence terminates if and only if it contains a term of A125001.
Is the sequence infinite?
EXAMPLE
a(2) = 23. Starting from a(1) = 2, insertion positions are considered from left to right for each digit. The numbers 20, 21, 22 are composite, while 23 is prime.
a(7) = 2200013. Starting from a(6) = 220013, insertion of the digit 0 is tested from left to right. Prepending 0 is not allowed; 2020013 is composite, while 2200013 is prime.
MATHEMATICA
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, 1+Length[d]}]]; Array[a, 22]
PROG
(Python)
from sympy import isprime
from itertools import islice
def anext(an):
s = str(an)
for c in "0123456789":
for k in range(int(c=="0"), len(s)+1):
w = s[:k] + c + s[k:]
if isprime(int(w)): return int(w)
def agen(an=2):
while an != None: yield an; an = anext(an)
CROSSREFS
Cf. A357436, the right-to-left counterpart, in which smallness of the inserted digit also has precedence over the insertion position.
Cf. A397083, which also considers insertion positions from left to right, but gives precedence to leftmostness of position over smallness of the inserted digit.
Cf. A356557, in which rightmostness of position has precedence over smallness of the inserted digit.
Search completed in 0.002 seconds
|