login
Search: a020994 -id:a020994
     Sort: relevance | references | number | modified | created      Format: long | short | data
Right-truncatable primes: every prefix is prime.
+10
56
2, 3, 5, 7, 23, 29, 31, 37, 53, 59, 71, 73, 79, 233, 239, 293, 311, 313, 317, 373, 379, 593, 599, 719, 733, 739, 797, 2333, 2339, 2393, 2399, 2939, 3119, 3137, 3733, 3739, 3793, 3797, 5939, 7193, 7331, 7333, 7393, 23333, 23339, 23399, 23993, 29399, 31193
OFFSET
1,1
COMMENTS
Primes in which repeatedly deleting the least significant digit gives a prime at every step until a single-digit prime remains. The sequence ends at a(83) = 73939133 = A023107(10).
The subsequence which consists of the following "chain" of consecutive right truncatable primes: 73939133, 7393913, 739391, 73939, 7393, 739, 73, 7 yields the largest sum, compared with other chains formed from subsets of this sequence: 73939133 + 7393913 + 739391 + 73939 + 7393 + 739 + 73 + 7 = 82154588. - Alexander R. Povolotsky, Jan 22 2008
Can also be seen as a table whose n-th row lists the n-digit terms; row lengths (0 for n >= 9) are given by A050986. The sequence can be constructed starting with the single-digit primes and appending, for each p in the list, the primes within 10*p and 10(p+1), formed by appending a digit to p. - M. F. Hasler, Nov 07 2018
REFERENCES
Roozbeh Hazrat, Mathematica: A Problem-Centered Approach, Springer London 2010, pp. 86-89
LINKS
Jens Kruse Andersen, Table of n, a(n) for n = 1..83 (The full list of terms, taken from link below)
Jens Kruse Andersen, Right-truncatable primes
I. O. Angell and H. J. Godwin, On Truncatable Primes, Math. Comput. 31, 265-267, 1977.
R. Schroeppel, HAKMEM item 33; "Russian Doll Primes", but with a slightly different definition.
Eric Weisstein's World of Mathematics, Truncatable Prime
MAPLE
s:=[1, 3, 7, 9]: a:=[[2], [3], [5], [7]]: l1:=1: l2:=4: do for j from l1 to l2 do for k from 1 to 4 do d:=[s[k], op(a[j])]: if(isprime(op(convert(d, base, 10, 10^nops(d)))))then a:=[op(a), d]: fi: od: od: l1:=l2+1: l2:=nops(a): if(l1>l2)then break: fi: od: seq(op(convert(a[j], base, 10, 10^nops(a[j]))), j=1..nops(a)); # Nathaniel Johnston, Jun 21 2011
MATHEMATICA
max = 100000; truncate[p_] := If[PrimeQ[q = Quotient[p, 10]], q, p]; ok[p_] := FixedPoint[ truncate, p] < 10; p = 1; A024770 = {}; While[ (p = NextPrime[p]) < max, If[ok[p], AppendTo[ A024770, p]]]; A024770 (* Jean-François Alcover, Nov 09 2011, after Pari *)
eppQ[n_]:=AllTrue[FromDigits/@Table[Take[IntegerDigits[n], i], {i, IntegerLength[ n]-1}], PrimeQ]; Select[Prime[Range[3400]], eppQ] (* The program uses the AllTrue function from Mathematica version 10 *) (* Harvey P. Dale, Jan 14 2015 *)
PROG
(Haskell)
import Data.List (inits)
a024770 n = a024770_list !! (n-1)
a024770_list = filter (\x ->
all (== 1) $ map (a010051 . read) $ tail $ inits $ show x) a038618_list
-- Reinhard Zumkeller, Nov 01 2011
(PARI) {fileO="b024770.txt"; v=vector(100); v[1]=2; v[2]=3; v[3]=5; v[4]=7; j=4; j1=1; write(fileO, "1 2"); write(fileO, "2 3"); write(fileO, "3 5"); write(fileO, "4 7"); until(0, if(j1>j, break); new=1; for(i=j1, j, if(new, j1=j+1; new=0); for(k=1, 9, z=10*v[i]+k; if(isprime(z), j++; v[j]=z; write(fileO, j, " ", z); )))); } \\ Harry J. Smith, Sep 20 2008
(PARI) for(n=2, 31193, v=n; while(isprime(n), c=n; n=(c-lift(Mod(c, 10)))/10); if(n==0, print1(v, ", ")); n=v); \\ Arkadiusz Wesolowski, Mar 20 2014
(PARI) A024770=vector(9, n, p=concat(apply(t->primes([t, t+1]*10), if(n>1, p)))) \\ The list of n-digit terms, 1 <= n <= 9. Use concat(%) to "flatten" it. - M. F. Hasler, Nov 07 2018
(Python)
from sympy import primerange
p = lambda x: list(primerange(x, x+10)); A024770 = p(0); i=0
while i<len(A024770): A024770+=p(A024770[i]*10); i+=1 # M. F. Hasler, Mar 11 2020
CROSSREFS
Supersequence of A085823, A202263. Subsequence of A012883, A068669. - Jaroslav Krizek, Jan 28 2012
Supersequence of A239747.
Cf. A033664, A024785 (left-truncatable primes), A032437, A020994, A052023, A052024, A052025, A050986, A050987, A069866, A077390 (left-and-right-truncatable primes), A137812 (left-or-right truncatable primes), A254751, A254753.
Cf. A237600 for the base-16 analog.
KEYWORD
nonn,base,easy,fini,full,nice,tabf
STATUS
approved
Left-truncatable primes: every suffix is prime and no digits are zero.
+10
43
2, 3, 5, 7, 13, 17, 23, 37, 43, 47, 53, 67, 73, 83, 97, 113, 137, 167, 173, 197, 223, 283, 313, 317, 337, 347, 353, 367, 373, 383, 397, 443, 467, 523, 547, 613, 617, 643, 647, 653, 673, 683, 743, 773, 797, 823, 853, 883, 937, 947, 953, 967, 983, 997, 1223
OFFSET
1,1
COMMENTS
Last term is a(4260) = 357686312646216567629137 (Angell and Godwin). - Eric W. Weisstein, Dec 11 1999
Can be seen as table whose rows list n-digit terms, 1 <= n <= 25. Row lengths are A050987. - M. F. Hasler, Nov 07 2018
LINKS
N. J. A. Sloane, Table of n, a(n) for n = 1..4260 (The full list, based on the De Geest web site)
I. O. Angell and H. J. Godwin, On Truncatable Primes, Math. Comput. 31, 265-267, 1977.
James Grime and Brady Haran, 357686312646216567629137, Numberphile video (2018).
Ernest G. Hibbs, Component Interactions of the Prime Numbers, Ph. D. Thesis, Capitol Technology Univ. (2022), see p. 33.
Eric Weisstein's World of Mathematics, Truncatable Prime
MAPLE
a:=[[2], [3], [5], [7]]: l1:=1: l2:=4: for n from 1 to 3 do for k from 1 to 9 do for j from l1 to l2 do d:=[op(a[j]), k]: if(isprime(op(convert(d, base, 10, 10^nops(d)))))then a:=[op(a), d]: fi: od: od: l1:=l2+1: l2:=nops(a): if(l1>l2)then break: fi: od: seq(op(convert(a[j], base, 10, 10^nops(a[j]))), j=1..nops(a)); # Nathaniel Johnston, Jun 21 2011
# second Maple program:
T:= proc(n) option remember; `if`(n=0, "", sort(select(isprime,
map(x-> seq(parse(cat(j, x)), j=1..9), [T(n-1)])))[])
end:
seq(T(n), n=1..4); # Alois P. Heinz, Sep 01 2021
MATHEMATICA
max = 2000; truncate[p_] := If[id = IntegerDigits[p]; FreeQ[id, 0] && (Last[id] == 3 || Last[id] == 7) && PrimeQ[q = FromDigits[ Rest[id]]], q, p]; ok[n_] := FixedPoint[ truncate, n] < 10; p = 5; A024785 = {2, 3, 5}; While[(p = NextPrime[p]) < max, If[ok[p], AppendTo[A024785, p]]]; A024785 (* Jean-François Alcover, Nov 09 2011 *)
d[n_]:=IntegerDigits[n]; ltrQ[n_]:=And@@PrimeQ[NestList[FromDigits[Drop[d[#], 1]]&, n, Length[d[n]]-1]]; Select[Range[1225], ltrQ[#]&] (* Jayanta Basu, May 29 2013 *)
FullList=Sort[Flatten[Table[FixedPointList[Select[Flatten[Table[Range[9]*10^Length@IntegerDigits[#[[1]]] + #[[i]], {i, Length[#]}]], PrimeQ] &, {i}], {i, {2, 3, 5, 7}}]]] (* Fabrice Laussy, Nov 10 2019 *)
PROG
(PARI) v=vector(4260); v[1]=2; v[2]=3; v[3]=5; v[4]=7; i=0; j=4; until(i>=j, i++; p=v[i]; P10=10^(1+log(p)\log(10)); for(k=1, 9, z=k*P10+p; if(isprime(z), j++; v[j]=z; ))); s=vector(4260); s=vecsort(v); for(i=1, j, write("b024785.txt", i, " ", s[i]); ); \\
(PARI) is_A024785(n, t=1)={until(t>10*p, isprime(p=n%t*=10)||return); n==p} \\ M. F. Hasler, Apr 17 2014
(PARI) A024785=vector(25, n, p=vecsort(concat(apply(p->select(isprime, vector(9, i, i*10^(n-1)+p)), if(n>1, p))))); \\ Yields the list of rows (n-digit terms, n = 1..25). Use concat(%) to flatten. There are faster variants using matrices (vectorv(9, i, 1)*p+[1..9]~*10^(n-1)*vector(#p, i, 1)) and/or predefined vectors, but they are less concise and this takes less than 0.1 sec. - M. F. Hasler, Nov 07 2018
(Haskell)
import Data.List (tails)
a024785 n = a024785_list !! (n-1)
a024785_list = filter (\x ->
all (== 1) $ map (a010051 . read) $ init $ tails $ show x) a038618_list
-- Reinhard Zumkeller, Nov 01 2011
(Python)
from sympy import isprime
def alst():
primes, alst = [2, 3, 5, 7], []
while len(primes) > 0:
alst += sorted(primes)
candidates = set(int(d+str(p)) for p in primes for d in "123456789")
primes = [c for c in candidates if isprime(c)]
return alst
print(alst()) # Michael S. Branicky, Apr 11 2021
CROSSREFS
Supersequence of A240768.
Cf. A033664, A032437, A020994, A024770 (right-truncatable primes), A052023, A052024, A052025, A050986, A050987, A077390 (left-and-right truncatable primes), A137812 (left-or-right truncatable primes), A254753.
KEYWORD
nonn,base,easy,fini,full,tabf
STATUS
approved
Every suffix is prime.
+10
21
2, 3, 5, 7, 13, 17, 23, 37, 43, 47, 53, 67, 73, 83, 97, 103, 107, 113, 137, 167, 173, 197, 223, 283, 307, 313, 317, 337, 347, 353, 367, 373, 383, 397, 443, 467, 503, 523, 547, 607, 613, 617, 643, 647, 653, 673, 683, 743, 773, 797, 823, 853, 883, 907, 937, 947
OFFSET
1,1
COMMENTS
Primes in which repeatedly deleting the most significant digit gives a prime at every step until a single-digit prime remains.
Every digit string containing the least significant digit is prime. - Amarnath Murthy, Sep 24 2003
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..66973 (first 8779 terms from T. D. Noe)
Eric Weisstein's World of Mathematics, Truncatable Prime.
MAPLE
T:= proc(n) option remember; `if`(n=0, "", select(isprime, [seq(seq(
seq(parse(cat(j, 0$(n-i), p)), p=[T(i-1)]), i=1..n), j=1..9)])[])
end:
seq(T(n), n=1..4); # Alois P. Heinz, Sep 01 2021
MATHEMATICA
h8pQ[n_]:=And@@PrimeQ/@Most[NestWhileList[FromDigits[Rest[ IntegerDigits[ #]]]&, n, #>0&]]; Select[Prime[Range[1000]], h8pQ] (* Harvey P. Dale, May 26 2011 *)
PROG
(PARI) fileO="b033664.txt"; lim=8779; v=vector(lim); v[1]=2; v[2]=3; v[3]=5; v[4]=7; j=4; write(fileO, "1 2"); write(fileO, "2 3"); write(fileO, "3 5"); write(fileO, "4 7"); p10=1; until(0, p10*=10; j0=j; for(k=1, 9, k10=k*p10; for(i=1, j0, if(j==lim, break(3)); z=k10+v[i]; if(isprime(z), j++; v[j]=z; write(fileO, j, " ", z); )))) \\ Harry J. Smith, Sep 20 2008
(Haskell)
a033664 n = a033664_list !! (n-1)
a033664_list = filter (all ((== 1) . a010051. read) .
init . tail . tails . show) a000040_list
-- Reinhard Zumkeller, Jul 10 2013
(Python)
from sympy import isprime, primerange
def ok(p): # does prime p satisfy the property
s = str(p)
return all(isprime(int(s[i:])) for i in range(1, len(s)))
print(list(filter(ok, primerange(1, 1000)))) # Michael S. Branicky, Sep 01 2021
(Python) # alternate for going to large numbers
def agen(maxdigits):
yield from [2, 3, 5, 7]
primestrs, digits, d = ["2", "3", "5", "7"], "0123456789", 1
while len(primestrs) > 0 and d < maxdigits:
cands = set(d+p for p in primestrs for d in "0123456789")
primestrs = [c for c in cands if c[0] == "0" or isprime(int(c))]
yield from sorted(map(int, (p for p in primestrs if p[0] != "0")))
d += 1
print([p for p in agen(11)]) # Michael S. Branicky, Sep 01 2021
KEYWORD
nonn,base,easy,nice
EXTENSIONS
More terms from Erich Friedman
STATUS
approved
Number of n-digit right-truncatable primes.
+10
18
4, 9, 14, 16, 15, 12, 8, 5, 0
OFFSET
1,1
COMMENTS
Right-truncatable means that the integer part of successive divisions by 10 always yields primes (or zero). - M. F. Hasler, Nov 07 2018
PROG
(PARI) A050986=vector(9, n, #p=concat(apply(t->primes([t, t+1]*10), if(n>1, p)))) \\ M. F. Hasler, Nov 07 2018
KEYWORD
base,nonn,easy,fini,full
EXTENSIONS
Edited by Ray Chandler, Mar 13 2007
a(9) = 0 added by M. F. Hasler, Nov 07 2018
STATUS
approved
Number of n-digit left-truncatable primes.
+10
18
4, 11, 39, 99, 192, 326, 429, 521, 545, 517, 448, 354, 276, 212, 117, 72, 42, 24, 13, 6, 5, 4, 3, 1, 0
OFFSET
1,1
COMMENTS
The sequence is well defined for any positive integer, with a(n) = 0 for n >= 25. But it makes sense to consider it to be full & finite. - M. F. Hasler, Nov 07 2018
PROG
(PARI) A050987=vector(25, n, #p=concat(apply(p->select(isprime, vector(9, i, i*10^(n-1)+p)), if(n>1, p)))) \\ M. F. Hasler, Nov 07 2018
(Python)
from sympy import isprime
def alst():
primes, alst = [2, 3, 5, 7], [4]
while len(primes) > 0:
candidates = set(int(d+str(p)) for p in primes for d in "123456789")
primes = [c for c in candidates if isprime(c)]
alst.append(len(primes))
return alst
print(alst()) # Michael S. Branicky, Apr 11 2021
KEYWORD
base,nonn,easy,fini,full
EXTENSIONS
Edited by Ray Chandler, Mar 13 2007
a(25) = 0 added by M. F. Hasler, Nov 07 2018
STATUS
approved
Every prefix (or suffix) of palindromic prime a(n) is prime (right/left-truncatable).
+10
18
2, 3, 5, 7, 313, 373, 797
OFFSET
1,1
LINKS
I. O. Angell and H. J. Godwin, On Truncatable Primes, Math. Comput. 31, 265-267, 1977.
C. K. Caldwell, Left and Right truncatable primes.
Eric Weisstein's World of Mathematics, Prime strings
KEYWORD
nonn,base,fini,full
AUTHOR
STATUS
approved
Substrings from the right are prime numbers (using only odd digits different from 5).
+10
12
3, 7, 13, 17, 37, 73, 97, 113, 137, 173, 197, 313, 317, 337, 373, 397, 773, 797, 937, 997, 1373, 1997, 3137, 3313, 3373, 3797, 7937, 9137, 9173, 9337, 9397, 13313, 33797, 39397, 79337, 79397, 91373, 91997, 99137, 99173, 99397, 139397, 379397
OFFSET
1,1
COMMENTS
Primes p with decimal expansion d_1 d_2 d_3 ... d_k such that the digits d_i are 1, 3, 7, or 9, and deleting 1, 2, 3, up to k-1 leading digits also produces a prime. For example, 9173 is a term because all of 9173, 173, 73, and 3 are primes. - N. J. A. Sloane, Jun 28 2022
LINKS
T. D. Noe, Table of n, a(n) for n = 1..58 [The complete list of terms]
C. Rivera, Prime strings
Eric Weisstein's World of Mathematics, Truncatable Prime.
EXAMPLE
173 is a term because 173, 73, and 3 are all primes. 371 is not a term because 371 and 1 are not primes. - N. J. A. Sloane, Jun 28 2022
MATHEMATICA
Select[Prime[Range[33000]], SubsetQ[{1, 3, 7, 9}, IntegerDigits[#]]&&AllTrue[Mod[#, 10^Range[ IntegerLength[ #]-1]], PrimeQ]&] (* Harvey P. Dale, Jun 28 2022 *)
PROG
(PARI) is(n)=my(d=digits(n)); for(i=1, n, if(!isprime(fromdigits(d[i..n])), return(0))); 1 \\ Charles R Greathouse IV, Jun 25 2017
KEYWORD
nonn,fini,full,base,nice
AUTHOR
EXTENSIONS
Single-digit terms added by Eric W. Weisstein.
STATUS
approved
Every suffix of palindromic prime a(n), containing no '0' digit, is prime (left-truncatable palindromic primes).
+10
12
2, 3, 5, 7, 313, 353, 373, 383, 797, 76367, 79397, 7693967, 799636997
OFFSET
1,1
LINKS
I. O. Angell and H. J. Godwin, On Truncatable Primes, Math. Comput. 31, 265-267, 1977.
C. K. Caldwell, Left and Right truncatable primes.
Eric Weisstein's World of Mathematics, Prime strings
MATHEMATICA
d[n_]:=IntegerDigits[n]; ltrQ[n_]:=And@@PrimeQ[NestList[FromDigits[Drop[d[#], 1]]&, n, Length[d[n]]-1]]; palQ[n_]:=Reverse[x=d[n]]==x; Select[Prime[Range[540000]], palQ[#]&&ltrQ[#]&] (* Jayanta Basu, Jun 02 2013 *)
KEYWORD
nonn,base,fini,full
AUTHOR
STATUS
approved
Every suffix of palindromic prime a(n) is prime (left-truncatable).
+10
11
2, 3, 5, 7, 313, 353, 373, 383, 797, 30103, 31013, 70607, 73037, 76367, 79397, 3002003, 7096907, 7693967, 700090007, 799636997, 70060906007, 3000002000003, 7030000000307, 300000020000003, 300001030100003, 310000060000013, 38000000000000000000083, 30000000004000300040000000003, 3000001000000000000000000000001000003
OFFSET
1,1
LINKS
I. O. Angell and H. J. Godwin, On Truncatable Primes, Math. Comput. 31, 265-267, 1977.
C. K. Caldwell, Left and Right truncatable primes.
Eric Weisstein's World of Mathematics, Prime strings
MATHEMATICA
d[n_]:=IntegerDigits[n]; ltrQ[n_]:=And@@PrimeQ[NestWhileList[FromDigits[Drop[d[#], 1]]&, n, #>9&]]; palQ[n_]:=Reverse[x=d[n]]==x; Select[Prime[Range[550000]], palQ[#]&&ltrQ[#]&] (* Jayanta Basu, Jun 02 2013 *)
PROG
(Python)
from sympy import isprime
from itertools import count, islice
def agen(verbose=False):
prime_strings, alst = {"3", "7"}, []
yield from [2, 3, 5, 7]
for digs in count(2):
new_prime_strings = set()
for p in prime_strings:
for d in "123456789":
ts = d + "0"*(digs-1-len(p)) + p
if isprime(int(ts)):
new_prime_strings.add(ts)
prime_strings |= new_prime_strings
pals = [int(s) for s in new_prime_strings if s == s[::-1]]
yield from sorted(pals)
if verbose: print("...", digs, len(prime_strings), time()-time0)
print(list(islice(agen(), 20))) # Michael S. Branicky, Apr 04 2022
KEYWORD
nonn,base
AUTHOR
EXTENSIONS
Inserted missing 31013 by Jayanta Basu, Jun 02 2013
a(27)-a(29) from Michael S. Branicky, Apr 04 2022
STATUS
approved
Numbers such that, in base 10, all their proper prefixes and suffixes represent primes.
+10
7
22, 23, 25, 27, 32, 33, 35, 37, 52, 53, 55, 57, 72, 73, 75, 77, 237, 297, 313, 317, 373, 537, 597, 713, 717, 737, 797, 2337, 2397, 2937, 3113, 3137, 3173, 3797, 5937, 5997, 7197, 7337, 7397, 29397, 31373, 37937, 59397, 73313, 739397
OFFSET
1,1
COMMENTS
A proper prefix (or suffix) of a number m is one which is neither void, nor identical to m.
Alternative definition: Slicing the decimal expansion of a(n) in any way into two nonempty parts, each part represents a prime number.
Every proper prefix of each member a(n) is a member of A024770, and every proper suffix is a member of A024785. Since these are finite sequences, a(n) is also finite. It has 45 members, the largest of which is 739397 and happens to be a prime.
The sequence is a union of A254753 and A020994.
A subsequence of A260181. - M. F. Hasler, Sep 16 2016
EXAMPLE
6 is not a member because its expansion cannot be sliced in two.
597 is a member because (5,97,59, and 7) are all primes.
2331 is excluded because 233 is prime, but 1 is not. - Gordon Hamilton, Feb 20 2015
MATHEMATICA
fQ[n_] := (p = {2, 3, 5, 7}; If[ Union@ Join[p, {Mod[n, 10]}] != p, {False}, Block[{idn = IntegerDigits@ n, lng = Floor@ Log10@ n}, Union@ PrimeQ@ Flatten@ Table[{FromDigits[ Take[idn, i]], FromDigits[ Take[idn, -lng + i - 1]]}, {i, lng}] == {True}]]); Select[ Range@1000000, fQ] (* Robert G. Wilson v, Feb 21 2015 *)
Select[Range[10, 750000], AllTrue[Flatten[Table[FromDigits/@TakeDrop[IntegerDigits[#], n], {n, IntegerLength[#]-1}]], PrimeQ]&] (* Harvey P. Dale, Feb 13 2024 *)
PROG
(PARI) slicesIntoPrimes(n, b=10) = {my(k=b); if(n<b, return(0); ); while(n\k>0, if(!isprime(n\k)||!isprime(n%k), return(0); ); k*=b; ); return(1); }
(Sage)
def breakIntoPrimes(n):
D=n.digits()
for i in [1..len(D)-1]:
if not(is_prime(sum(D[i:][j]*10^j for j in range(len(D[i:])))) and is_prime(sum(D[:i][j]*10^j for j in range(len(D[:i]))))):
return False
else:
continue
return True
[n for n in [10..1000] if breakIntoPrimes(n)] # Tom Edgar, Feb 20 2015
KEYWORD
nonn,base,fini,full
AUTHOR
Stanislav Sykora, Feb 15 2015
STATUS
approved

Search completed in 0.018 seconds