login
Primes p such that p + (product of digits of p) is prime and p - (product of digits of p) is prime.
3

%I #56 Mar 21 2020 16:37:59

%S 23,29,83,101,103,107,109,293,307,347,349,401,409,431,439,503,509,601,

%T 607,653,659,677,701,709,743,809,907,1009,1013,1019,1021,1031,1033,

%U 1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1123,1201,1297,1301,1303,1307,1409,1423,1489,1523

%N Primes p such that p + (product of digits of p) is prime and p - (product of digits of p) is prime.

%C Intersection of A157677 and A225319.

%C Contains A056709. - _Robert Israel_, Apr 13 2015

%H Michael De Vlieger, <a href="/A227217/b227217.txt">Table of n, a(n) for n = 1..10000</a>

%e 431 is prime, 431 + (4*3*1) = 443 is prime, and 431 - (4*3*1) = 419 is prime. So, 431 is a term in the sequence.

%p filter:= proc(n) local m;

%p if not isprime(n) then return false fi;

%p m:= convert(convert(n,base,10),`*`);

%p if m = 0 then return true fi;

%p isprime(n+m) and isprime(n-m)

%p end proc:

%p select(filter, [seq(2*i+1,i=5..10000)]); # _Robert Israel_, Apr 13 2015

%t fQ[n_] := Block[{d = IntegerDigits@ n}, PrimeQ[n + Times @@ d] && PrimeQ[n - Times @@ d]]; Select[Prime@ Range@ 250, fQ] (* _Michael De Vlieger_, Apr 12 2015 *)

%o (Python)

%o from sympy import isprime, primerange

%o def DP(n):

%o p = 1

%o for i in str(n):

%o p *= int(i)

%o return p

%o for pn in primerange(1, 2000):

%o dpn = DP(pn)

%o if isprime(pn-dpn) and isprime(pn+dpn):

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

%o # Simplified by _Derek Orr_, Apr 10 2015

%o (Sage)

%o [p for p in primes_first_n(1000) if ((p-prod(Integer(p).digits(base=10))) in Primes() and (p+prod(Integer(p).digits(base=10))) in Primes())] # _Tom Edgar_, Sep 19 2013

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

%Y Cf. A007954, A056709, A157677, A225319.

%K nonn,base

%O 1,1

%A _Derek Orr_, Sep 19 2013

%E More terms from _Derek Orr_, Apr 10 2015