login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

Smallest prime starting with n that does not appear earlier.
3

%I #32 Nov 11 2020 19:05:36

%S 11,2,3,41,5,61,7,83,97,101,113,127,13,149,151,163,17,181,19,2003,211,

%T 223,23,241,251,263,271,281,29,307,31,3203,331,347,353,367,37,383,397,

%U 401,419,421,43,443,457,461,47,487,491,503,5101,521,53,541,557,563,571,587,59,601,613,6203,631,641,653,661,67,683,691,701

%N Smallest prime starting with n that does not appear earlier.

%C According to a comment in A018800, every term exists. So the sequence is a permutation of the primes. Indeed, every prime p appears in the sequence either as the p-th term or earlier.

%H Peter J. C. Moses, <a href="/A258337/b258337.txt">Table of n, a(n) for n = 1..5000</a>

%H <a href="/index/Pri#piden">Index entries for primes involving decimal expansion of n</a>

%F For n>=2, a(n) >= prime(n-1). The equality holds iff prime(n-1) did not already appear as a(k), k<n.

%p N:= 100: # to get a(1) to a(N)

%p for n from 1 to N do

%p p:= n;

%p if n < 10 then

%p p1:= 0

%p else

%p p1:= A[floor(n/10)];

%p fi;

%p if isprime(p) and p > p1 then

%p A[n]:= p

%p else

%p for d from 1 while not assigned(A[n]) do

%p for i from 1 to 10^d-1 do

%p p:= 10^d*n+i;

%p if p > p1 and isprime(p) then

%p A[n]:= p;

%p break

%p fi;

%p od

%p od

%p fi

%p od:

%p seq(A[i],i=1..N); # _Robert Israel_, Jun 29 2015

%o (PARI) sw(m,n)=d1=digits(n);d2=digits(m);for(i=1,min(#d1,#d2),if(d1[i]!=d2[i],return(0)));1

%o v=[];n=1;while(n<70,k=1;while(k<10^3,p=prime(k);if(sw(p,n)&&!vecsearch(vecsort(v),p),v=concat(v,p);k=0;n++);k++));v \\ _Derek Orr_, Jun 13 2015

%o (Haskell)

%o import Data.List (isPrefixOf, delete)

%o a258337 n = a258337_list !! (n-1)

%o a258337_list = f 1 $ map show a000040_list where

%o f x pss = g pss where

%o g (qs:qss) = if show x `isPrefixOf` qs

%o then (read qs :: Int) : f (x + 1) (delete qs pss)

%o else g qss

%o -- _Reinhard Zumkeller_, Jul 01 2015

%Y Cf. A000040, A018800, A030665, A062584, A258190, A258339.

%K nonn,base

%O 1,1

%A _Vladimir Shevelev_, May 27 2015