Project Eluer - 20

来源:互联网 发布:java包装简历 编辑:程序博客网 时间:2024/05/16 10:01

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!


翻译:

n!表示 n*(n-1)*....*3*2*1 的积。 10!= 3628800, 所有数位之和为 3+6+2+8+8+0+0 = 27 , 找出100的阶层的的所有数位之和?

 

思路:

看到这个题,就想到了python,只要有大数库,这个问题就很好解决了。代码如下:

product = 1for i in range(1,100+1):product *= iprint productresut = 0for i in str(product):resut += int(i)print resut

输出结果:

100! = 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
所有数位之和 = 648


0 0
原创粉丝点击