首页 > 代码库 > 欧拉计划(python) problem 20

欧拉计划(python) problem 20

Factorial digit sum

Problem 20

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!


Answer:
648
Completed on Fri, 30 Jan 2015, 15:06

python code:

import math
sqrt=math.sqrt


result=1
for i in range(1,101):
    result*=i
temp=str(result)
result=0
k=len(temp)
for i in range(0,k):
    result+=int(temp[i])
print(result)


time: <1s

欧拉计划(python) problem 20