login
Prime numbers such that the product of their digits equals twice the number of their digits times the sum of their digits.
1

%I #17 Jun 30 2023 16:32:23

%S 347,743,15581,42451,51581,54421,58151,58511,81551,112583,115823,

%T 118253,121853,122443,123581,125183,125813,128153,128351,132851,

%U 135281,138251,144223,152183,152381,153281,158231,181253,181523,185123,211583,214243,215183,215381,218513,218531,223441,235181,235811,238151,242413

%N Prime numbers such that the product of their digits equals twice the number of their digits times the sum of their digits.

%H Michael S. Branicky, <a href="/A343701/b343701.txt">Table of n, a(n) for n = 1..10000</a>

%e 347 is a 3-digit prime number. The product of its digits is 84. The sum of its digits is 14. As 84 = 2*3*14, this number is in the sequence.

%p q:= n-> (l-> mul(i,i=l)=2*nops(l)*add(i,i=l))(convert(n, base, 10)):

%p select(q, [ithprime(j)$j=1..100000])[]; # _Alois P. Heinz_, May 30 2021

%t Select[Range[1000000], PrimeQ[#] && Times@@IntegerDigits[#] == 2 Length[IntegerDigits[#]] Total[IntegerDigits[#]] &]

%t Select[Prime[Range[22000]],Times@@IntegerDigits[#]==2(IntegerLength[#]Total[ IntegerDigits[ #]])&] (* _Harvey P. Dale_, Jun 30 2023 *)

%o (Python)

%o from math import prod

%o from sympy import isprime

%o from sympy.utilities.iterables import multiset_permutations as mp

%o from itertools import count, islice, combinations_with_replacement as mc

%o def c(s):

%o d = list(map(int, s))

%o return prod(d) == 2*len(d)*sum(d)

%o def agen():

%o for d in count(2):

%o okset = set()

%o for cand in ("".join(m) for m in mc("987654321", d)):

%o if c(cand):

%o for p in mp(cand, d):

%o t = int("".join(p))

%o if isprime(t): okset.add(t)

%o yield from sorted(okset)

%o print(list(islice(agen(), 41))) # _Michael S. Branicky_, Nov 30 2022

%Y Cf. A064155.

%K nonn,base

%O 1,1

%A _Tanya Khovanova_, May 26 2021