login
Primes that remain prime when a single digit 7 is inserted between any two consecutive digits or as the leading or trailing digit.
12

%I #20 Jul 23 2023 01:52:16

%S 3,19,97,433,487,541,691,757,853,1471,2617,2953,4507,6481,7351,7417,

%T 8317,13177,31957,42457,46477,47977,50077,59053,71917,73897,74377,

%U 77479,77743,77761,79039,99103,175687,220897,271177,360973

%N Primes that remain prime when a single digit 7 is inserted between any two consecutive digits or as the leading or trailing digit.

%H Harvey P. Dale, <a href="/A215420/b215420.txt">Table of n, a(n) for n = 1..63</a> (all terms up to and including the 1 millionth prime)

%e 59053 is prime as are 590537, 590573, 590753, 597053, 579053, and 759053.

%p A215420:=proc(q,x)

%p local a,b,c,d,i,n,ok;

%p for n from 1 to q do

%p a:=ithprime(n); b:=0; while a>0 do b:=b+1; a:=trunc(a/10); od;

%p a:=ithprime(n); ok:=1;

%p for i from 0 to b do

%p c:=a+9*10^i*trunc(a/10^i)+10^i*x; if not isprime(c) then ok:=0; break; fi;

%p od;

%p if ok=1 then print(ithprime(n)); fi;

%p od; end:

%p A215420(1000,7);

%t Select[Prime[Range[31000]],AllTrue[FromDigits/@Table[Insert[ IntegerDigits[ #],7,n],{n,IntegerLength[#]+1}],PrimeQ]&] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Oct 29 2020 *)

%Y Cf. A215417, A215418, A215419, A215421.

%K nonn,base

%O 1,1

%A _Paolo P. Lava_, Aug 10 2012