n!=n*(n-1)*……1
例如:10!=10X9X8X7X6X5X4X3X2X1=3628800
所以10!的阶乘数字和为3+6+2+8+8+0+0=27
求100!的阶乘数字和
---------python--------------
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __author__ = lanzili __mtime__ = '2017/10/17' # code is far away from bugs with the god animal protecting I love animals. They taste delicious. ┏┓ ┏┓ ┏┛┻━━━┛┻┓ ┃ ☃ ┃ ┃ ┳┛ ┗┳ ┃ ┃ ┻ ┃ ┗━┓ ┏━┛ ┃ ┗━━━┓ ┃ 神兽保佑 ┣┓ ┃ 永无BUG! ┏┛ ┗┓┓┏━┳┓┏┛ ┃┫┫ ┃┫┫ ┗┻┛ ┗┻┛ """
import math import time start=time.clock() string=str(math.factorial(100)) sum=0 for i in string: sum+=int(i) end=time.clock() print(sum) print(end-start)
小技巧在于将big int 转化为字符串这样一个迭代器,然后可以通过for循环累加来得到结果