欧拉计划(python) problem 20

时间:2015-01-31 13:00:55   收藏:0   阅读:177

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!