Finding the sum of the product of factorials of the digits of numbers

I want to calculate the sum of the product of factorials of the digits of numbers. So for example, when $$n=467$$ I get:

$$n=467\space\to\space\left(4!\right)\cdot\left(6!\right)\cdot\left(7!\right)=87091200\space\to\space8+7+0+9+1+2+0+0=27\tag1$$

So, when $$n=467$$ I must get $$27$$.

How can I write fast code to do that? Thanks in advance and Merry Christmas to everybody.

I wrote the following code:

Total@
IntegerDigits[
Product[
Factorial[Part[IntegerDigits[n], k]],
{k, 1, Length[IntegerDigits[n]]}
]
]


Which does the job but is really slow.

• I don't think there's a point to parallelization here. There are only ten possible factorials (digits 0 through 9), and you can just memoize those and look them up. Dec 25 '21 at 22:40
• A little more compact is f[n_] := Total@IntegerDigits[Times @@ Factorial[IntegerDigits[n]]]. Dec 26 '21 at 0:40
• Carl's suggestion to memoize the factorials for the digits seems to give a small speedup (~10%) over bbgodfrey's formula directly. Fairly small improvement, might vary between machines. facts = Factorial[Range[10] - 1]; f[n_] := Total@IntegerDigits[Times @@ facts[[IntegerDigits[n] + 1]]] Dec 26 '21 at 6:33
• Try this one liner: Composition[Total, IntegerDigits, Times @@ # &, Factorial, IntegerDigits][n] Dec 26 '21 at 13:55
• All solutions given in the comments require about ten seconds on my computer to process a ten-million-digit number. The solution in the question is much slower. Dec 26 '21 at 21:22
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 4, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}