login
Primes p such that p - d and p + d are also primes, where d is the smallest nonzero digit of p.
2

%I #15 Nov 26 2024 02:17:11

%S 67,607,6977,68897,69067,69997,79867,80677,88867,97967,609607,660067,

%T 669667,676987,678767,697687,707677,766867,777677,786697,866087,

%U 879667,880667,886987,899687,906707,909767,966997,990967,6069977,6096907,6097997,6678877

%N Primes p such that p - d and p + d are also primes, where d is the smallest nonzero digit of p.

%C Intersection of A245744 and A245745.

%C The smallest nonzero digit of a(n) is 6, and the least significant digit of a(n) is 7.

%H Robert Israel, <a href="/A245878/b245878.txt">Table of n, a(n) for n = 1..10000</a>

%e The prime 607 is in the sequence because 607 - 6 = 601 and 607 + 6 = 613 are both primes.

%p f:= proc(x) local L,i,y;

%p L:= subs(1=6,2=7,3=8,4=9, convert(x,base,5));

%p if not member(6,L) then return NULL fi;

%p y:= add(L[i]*10^(i-1),i=1..nops(L));

%p if isprime(y) and isprime(y-6) and isprime(y+6) then y else NULL fi

%p end proc:

%p map(f, [seq(2+5*k,k=1..10000)]); # _Robert Israel_, Nov 25 2024

%t pdQ[p_]:=Module[{c=Min[DeleteCases[IntegerDigits[p],0]]},AllTrue[p+{c,-c},PrimeQ]]; Select[Prime[Range[460000]],pdQ] (* _Harvey P. Dale_, Feb 26 2023 *)

%o (PARI) s=[]; forprime(p=2, 7000000, v=vecsort(digits(p),,8); d=v[1+!v[1]]; if(isprime(p-d) && isprime(p+d), s=concat(s, p))); s

%o (Python)

%o from sympy import isprime

%o from sympy import prime

%o for n in range(1, 10**6):

%o s=prime(n)

%o lst = []

%o for i in str(s):

%o if i != '0':

%o lst.append(int(i))

%o if isprime(s+min(lst)) and isprime(s-min(lst)):

%o print(s, end=', ')

%o # _Derek Orr_, Aug 13 2014

%Y Cf. A245742, A245743, A245744, A245745, A245877.

%K nonn,base,look

%O 1,1

%A _Colin Barker_, Aug 05 2014