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!
Kod:
def factorial(num: int):
fac = 1
for _ in range(1, num+1):
fac = fac*_
return fac
def nsum(num):
summ = []
for _ in str(num):
summ.append(int(_))
return sum(summ)
print(nsum(factorial(100)))
https://projecteuler.net/problem=20