Back to Project Euler

Previous Problem Next Problem

Problem 20: Factorial Digit Sum

\(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!\).

Solution

Just like in Problem 16, the most efficient approach is to just calculate the number and sum its digits.

Python Code

from math import factorial
p20 = lambda n=100: sum(map(int, str(factorial(n))))

Previous Problem Next Problem

Back to Project Euler