login
Primes p with nonzero digits such that p + product_of_digits and p - product_of_digits are both prime.
1

%I #46 Oct 16 2024 14:52:52

%S 23,29,83,293,347,349,431,439,653,659,677,743,1123,1297,1423,1489,

%T 1523,1657,1867,2239,2377,2459,2467,2543,2579,2663,2753,3163,3253,

%U 3271,3329,3457,3461,3581,3691,3727,3833,3947,3967,4129,4253,4297,4423,4567,4957,5323,5381,5651

%N Primes p with nonzero digits such that p + product_of_digits and p - product_of_digits are both prime.

%C Numbers with nonzero digits in A227217; the non-degenerate cases, so to speak.

%C Intersection of primes with nonzero digits in A157677 and A225319.

%H Vincenzo Librandi, <a href="/A229176/b229176.txt">Table of n, a(n) for n = 1..1000</a>

%e 743 is prime.

%e 743 - (7*4*3) = 659 is prime.

%e 743 + (7*4*3) = 827 is prime.

%e So, 743 is a member of this sequence.

%p A007954 := proc(n)

%p mul(d, d=convert(n, base, 10))

%p end proc:

%p isA229176 := proc(n)

%p if isprime(n) and A007954(n) <> 0 then

%p isprime(n+A007954(n)) and isprime(n-A007954(n)) ;

%p simplify(%) ;

%p else

%p false;

%p end if;

%p end proc:

%p for n from 1 to 10000 do

%p if isA229176(n) then

%p printf("%d,",n) ;

%p end if;

%p end do:

%t id[x_] := IntegerDigits[x]; ti[x_] := Times @@ id[x]; m=5000; Select[Range[3,m,2], PrimeQ[#] && Min[id[#]] > 0 && PrimeQ[#+ti[#]] && PrimeQ[#-ti[#]]&] (* _Zak Seidov_, Oct 02 2013 *)

%t t@n_ := Block[{p = Times @@ IntegerDigits@n},

%t If[p == 0, {0}, n + {-p, p}]]; Select[Prime@Range@1000,

%t AllTrue[t@#, PrimeQ] &] (* _Hans Rudolf Widmer_, Dec 13 2021 *)

%o (Python)

%o import sympy

%o from sympy import isprime

%o def DP(n):

%o p = 1

%o for i in str(n):

%o p *= int(i)

%o return p

%o {print(n, end=', ') for n in range(10**4) if DP(n) and isprime(n) and isprime(n+DP(n)) and isprime(n-DP(n))}

%o # Simplified by _Derek Orr_, Mar 22 2015

%o (PARI) forprime(p=1,10^4,d=digits(p);P=prod(i=1,#d,d[i]);if(P&&isprime(p+P)&&isprime(p-P),print1(p,", "))) \\ _Derek Orr_, Mar 22 2015

%Y Cf. A227217, A157677, A225319.

%K nonn,base,easy

%O 1,1

%A _Derek Orr_, Sep 30 2013