码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 20

时间:2015-01-31 13:00:55      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://blog.csdn.net/zhangzhengyi03539/article/details/43318955

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!