Python Implementation of Problem 20

View source code here on GitHub!

Includes

Problem Solution

Project Euler Problem 20

If I need to do bigger numbers than this, or multiple times, a recursive approach will almost certainly be better. This works for now, though.

Problem:

n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 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!

python.src.p0020.main() int
 1"""
 2Project Euler Problem 20
 3
 4If I need to do bigger numbers than this, or multiple times, a recursive
 5approach will almost certainly be better. This works for now, though.
 6
 7Problem:
 8
 9n! means n × (n − 1) × ... × 3 × 2 × 1
10
11For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
12and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
13
14Find the sum of the digits in the number 100!
15"""
16from math import factorial
17
18
19def main() -> int:
20    return sum(int(x) for x in repr(factorial(100)))

Tags: large-numbers, digit-sum, factorial