Published: March 3, 2024

Project Euler

Problem 20 - Factorial Digit Sum

Problem

This problem comes from Project Euler 20

Problem

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

For example, 10!=10×9××3×2×1=362880010! = 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=273+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))