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”).
%I #23 Jun 01 2019 11:10:21
%S 11,223,31,401,547,619,773,8581,9109,10223,1129,12073,130553,14563,
%T 150011,161471,17257,18803,191189,20809,210557,225383,237091,240209,
%U 2509433,2613397,277429,283211,2901649,308153,313409,3204139,3300613,3419063,3507739,360091,3727313,3806347,3930061,4045421,41018911
%N a(n) is the smallest prime p whose decimal expansion begins with n and is such that the next prime is p+2n, or -1 if no such prime exists.
%H Chai Wah Wu, <a href="/A308438/b308438.txt">Table of n, a(n) for n = 1..100</a>
%e For n = 5, 547 is a prime starting with 5, and the next prime after 547 is 557 = 547 + 2*5. Since this is the least number with these properties, a(5) = 547.
%p f:= proc(n) local d,p,q;
%p for d from 0 do
%p p:= nextprime(n*10^d-1);
%p do
%p q:= nextprime(p);
%p if q - p = 2*n then return p fi;
%p if q >= (n+1)*10^d then break fi;
%p p:= q;
%p od;
%p od;
%p end proc:
%p map(f, [$1..50]);
%o (Python)
%o from sympy import nextprime
%o def A308438(n):
%o l, p = 1, nextprime(n)
%o while True:
%o q = nextprime(p)
%o if q-p == 2*n:
%o return p
%o p = q
%o if p >= (n+1)*l:
%o l *= 10
%o p = nextprime(n*l) # _Chai Wah Wu_, May 31 2019
%Y Cf. A018800, A030665.
%K nonn,base,look
%O 1,1
%A _J. M. Bergot_ and _Robert Israel_, May 30 2019