Project Euler Problem 20
n! means n times (n - 1) times cdots times 3 times 2 times 1.
Solution
Answer: 648
We need the sum of the digits of $100!$.
1. Mathematical approach
Compute:
$$100! = 100 \times 99 \times 98 \times \cdots \times 2 \times 1$$
Then convert the resulting integer to digits and sum them.
Python handles arbitrarily large integers, so this is straightforward.
2. Clean Python code
import math
n = math.factorial(100)
digit_sum = sum(int(digit) for digit in str(n))
print(digit_sum)
3. Quick correctness check
We know:
- $10! = 3628800$, whose digit sum is $27$ (matches the example).
- Computing $100!$ exactly and summing its digits gives:
$$648$$
This is the known verified result for Project Euler Problem 20.
Answer: 648