login
A062584
a(n) is the smallest prime whose digits include the digits of n as a substring.
20
101, 11, 2, 3, 41, 5, 61, 7, 83, 19, 101, 11, 127, 13, 149, 151, 163, 17, 181, 19, 1201, 211, 223, 23, 241, 251, 263, 127, 281, 29, 307, 31, 1321, 233, 347, 353, 367, 37, 383, 139, 401, 41, 421, 43, 443, 457, 461, 47, 487, 149, 503, 151, 521, 53, 541, 557, 563
OFFSET
0,1
COMMENTS
a(0) = 101 is the first term where a(n) has two more digits than n. a(665808) = 106658081 is the first term where a(n) has three more digits than n. For which n does a(n) first have four more digits than n? Is lim sup a(n)/n infinite? - Charles R Greathouse IV, Jun 23 2017
Decide how many elements you want to find. Then for every prime, check all substrings to see if they are the first to be in some n. If you've found all values a(n), then you want to stop. - David A. Corneth, Jun 24 2017
FORMULA
a(n) = prime(A082058(n)). - Giovanni Resta, Apr 29 2017
EXAMPLE
0 first occurs in 101. 14 first occurs as a substring in 149.
MATHEMATICA
Do[k = 1; While[ StringPosition[ ToString[Prime[k]], ToString[n]] == {}, k++ ]; Print[ Prime[k]], {n, 0, 62} ]
(* Second program *)
Function[s, Table[FromDigits@ FirstCase[s, w_ /; SequenceCount[w, IntegerDigits@ n] > 0], {n, 0, 56}]]@ IntegerDigits@ Prime@ Range[10^4] (* Michael De Vlieger, Jun 24 2017 *)
With[{prs=Prime[Range[300]]}, Table[SelectFirst[prs, SequenceCount[ IntegerDigits[#], IntegerDigits[ n]]>0&], {n, 0, 60}]] (* Requires Mathematica version 10 or later *) (* Harvey P. Dale, Dec 06 2018 *)
PROG
(Haskell)
import Data.List (isInfixOf)
a062584 n = head [p | p <- a000040_list, show n `isInfixOf` show p]
-- Reinhard Zumkeller, Dec 29 2011
(PARI) build(root, prefixLen, suffixLen)=my(v=List(), t); for(i=10^(prefixLen-1)\1, 10^prefixLen-1, t=eval(Str(i, root))*10^suffixLen; for(n=t, t+10^suffixLen-1, listput(v, n))); Vec(v)
buildLen(n, d)=my(v=[]); for(i=0, d, v=concat(v, build(n, i, d-i))); Set(v)
a(n)=if(n==0, return(101)); my(d, v); while(1, v=buildLen(n, d); for(i=1, #v, if(isprime(v[i]), return(v[i]))); d++) \\ Charles R Greathouse IV, Jun 23 2017
(PARI) first(n) = my(res = vector(n), todo = n, g); forprime(p = 2, , d = digits(p); for(i=1, #d, if(d[i]!=0, g = d[i]; if(res[g]==0, res[g]=p; todo--); for(j=1, #d-i, g=10*g+d[i+j]; if(g>n, next(2)); if(res[g]==0, res[g]=p; todo--)))); if(todo==0, return(concat([101], res)))) \\ David A. Corneth, Jun 23 2017
(Python)
from sympy import nextprime
def a(n):
p, s = 2, str(n)
while s not in str(p): p = nextprime(p)
return p
print([a(n) for n in range(57)]) # Michael S. Branicky, Dec 02 2021
CROSSREFS
Cf. A082058, A018800, A060386. Similar to but different from A068164. E.g., a(133) = 4133, but A068164(133) = 1033.
Sequence in context: A266460 A341634 A060386 * A085054 A084045 A085419
KEYWORD
easy,nonn,base,nice
AUTHOR
Jason Earls, Jul 03 2001
EXTENSIONS
More terms from Lior Manor, Jul 08 2001
Corrected by Larry Reeves (larryr(AT)acm.org), Jul 10 2001
Further correction from Reinhard Zumkeller, Oct 14 2001
Name clarified by Jon E. Schoenfield, Dec 04 2021
STATUS
approved