## $n!$ means $n \times (n – 1) \times \cdots \times 3 \times 2 \times 1$.

For example, $10! = 10 \times 9 \times \cdots \times 3 \times 2 \times 1 = 3628800$,and the sum of the digits in the number $10!$ is $3 + 6 + 2 + 8 + 8 + 0 + 0 = 27$.

Find the sum of the digits in the number $100!$.

### Calculating $100!$ directly and then adding up the digits would be quite complicated, so let’s find a smarter approach.

In general, when calculating $n!$, numbers are multiplied together. Anytime you multiply by a multiple of 10, a zero is appended to the end of the number. All multiples of 2 and 5, when multiplied together, yield a multiple of 10. Since there are more multiples of 2 than multiples of 5 in $100!$, we know that $100!$ ends in lots of zeros, but we cannot directly use these zeros for the sum of digits.

To solve this problem, let’s implement the Python algorithm to calculate the sum of digits in $100!$. Use the built-in factorial function (math.factorial) to calculate $100!$, then convert the result into a string to be able to iterate over each digit, convert each digit back to an integer, and accumulate the total:

“`python

import math

num = math.factorial(100)

digits = [int(d) for d in str(num)]

sum_digits = sum(digits)

print(sum_digits)

“`

If you run this Python code, it will provide the answer: the sum of the digits in the number $100!$ is 648.

##### More Answers:

Number Letter CountsMaximum Path Sum I

Counting Sundays