ZLA
AST

Problem 20 - Factorial Digit Sum

Project Euler
Post Image
March 6, 2024
Read Time: 1 min

Problem

This problem comes from Project Euler 20

Problem

n! n! means n×(n1)××3×2×1 n \times (n - 1) \times \cdots \times 3 \times 2 \times 1 .

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

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

Solution

Another simple problem.

  1. Calculate 100! 100!
  2. Convert the number into a string
  3. Iterate over the string and convert into a number array
  4. Sum the array

Code

# Project Euler: Problem 20
# Factorial digit sum

from math import factorial as f

number = f(100)
number_list = [int(i) for i in str(number)]
print(sum(number_list))