%I #24 Jul 06 2024 13:39:45
%S 2,3,5,7,167,523,617,761,1427,2417,2741,4127,4217,4271,4721,126241,
%T 126421,146221,212461,216421,221461,224611,226141,241261,242161,
%U 246121,261241,262411,264211,421621,426211,621241,642121,642211,1111457,1111547,1115417,1117451
%N Let p = x1x2x3...xk be a prime in base 10 with k digits. The sequence gives the primes p such that x1*x2*x3*...xk = k*(x1 + x2 + x3 + ... + xk).
%H Michael S. Branicky, <a href="/A064155/b064155.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..100 from Harry J. Smith)
%e 167 belongs to the sequence because 1*6*7 = 42 and 3*(1+6+7) = 42.
%t Select[Prime@Range@1000000, Plus@@(i=IntegerDigits@#)*Length@i == Times@@i&] (*_Hans Rudolf Widmer_, Jun 13 2024*)
%o (PARI) ProdD(x)= { local(p); p=1; while (x>9 && p>0, p*=(x-10*(x\10)); x\=10); return(p*x) }
%o SumD(x)= { local(s); s=0; while (x>9, s+=x-10*(x\10); x\=10); return(s + x) }
%o digitsIn(x)= { local(d); if (x==0, return(1)); d=1 + log(x)\log(10); if (10^d == x, d++, if (10^(d-1) > x, d--)); return(d) }
%o { n=r=0; for (m=1, 10^9, r=nextprime(r+1); if ((p=ProdD(r)) && p == digitsIn(r)*SumD(r), write("b064155.txt", n++, " ", r); if (n==100, break)) ) } \\ _Harry J. Smith_, Sep 09 2009
%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) == len(d)*sum(d)
%o def agen():
%o yield from (2, 3, 5, 7)
%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(), 38))) # _Michael S. Branicky_, Nov 30 2022
%K easy,nonn,base
%O 1,1
%A _Felice Russo_, Sep 14 2001