%I #26 Sep 25 2023 14:59:34
%S 9,1,6,12,40,30,84,224,144,45,605,495,1170,1092,210,240,2448,4896,
%T 15846,3420,1750,462,15939,0,8100,67925,80730,19656,11774,164430,930,
%U 29760,197472,0,0,1260,23976,50616,54834,395200,1248860,4253340,75852,0,42570
%N Number of positive integers with n digits whose digit sum is equal to its digit product.
%H Chai Wah Wu, <a href="/A297815/b297815.txt">Table of n, a(n) for n = 1..10000</a>
%e The only term with two digits is 22: 2 * 2 = 2 + 2.
%t cperm[w_] := Length[w]!/Times @@ ((Last /@ Tally[w])!); ric[s_, p_, w_, tg_] := Block[{d}, If[tg == 0, If[s == p, tot += cperm@ w], Do[ If[p*d > s + d + (tg-1)*9, Break[]]; ric[s+d, p*d, Append[w,d], tg-1], {d, Last@ w, 9}]]]; a[n_] := (tot=0; ric[#, #, {#}, n-1] & /@ Range[9]; tot); Array[a, 45] (* _Giovanni Resta_, Feb 05 2018 *)
%o (Python)
%o import math
%o def digitProd(natNumber):
%o digitProd = 1
%o for letter in str(natNumber):
%o digitProd *= int(letter)
%o return digitProd
%o def digitSum(natNumber):
%o digitSum = 0
%o for letter in str(natNumber):
%o digitSum += int(letter)
%o return digitSum
%o for n in range(24):
%o count = 0
%o for a in range(int(math.pow(10,n)), int(math.pow(10, n+1))):
%o if digitProd(a) == digitSum(a):
%o count += 1
%o print(n+1, count)
%o (Python)
%o from sympy.utilities.iterables import combinations_with_replacement
%o from sympy import prod, factorial
%o def A297815(n):
%o f = factorial(n)
%o return sum(f//prod(factorial(d.count(a)) for a in set(d)) for d in combinations_with_replacement(range(1,10),n) if prod(d) == sum(d)) # _Chai Wah Wu_, Feb 06 2018
%Y Cf. A034710, A061672.
%K nonn,base
%O 1,1
%A _Reiner Moewald_, Jan 06 2018
%E a(10) and a(23) corrected by and a(25)-a(45) from _Giovanni Resta_, Feb 05 2018