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
LINKS
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
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