means .
For example, , and the sum of the digits in the number is .
Find the sum of the digits in the number .
https://projecteuler.net/problem=20
Trying in my unsuspecting calculator overflows it. It’s an unimaginably big number. It is approximately . For comparison, the number of atoms in the observable universe is estimated to be somewhere on the order of !! (Factorial definitely not intended).
Calculating this directly is just doing 100 multiplications. Storing this number is a different story, however. With languages like C, some preliminary work needs to be done. With Python and its bignum
support, the answer is just a few lines.
import math total = 0 for digit in str(math.factorial(100)): total += int(digit) print(total)
The answer is . Easy-peasy. Of course, there’s some stuff going on under the hood such as Python’s implementation of factorial
or bignum
. I might not need to pop open the hood every time I go driving, but it’s good to know what’s under there.