![](https://i-blog.csdnimg.cn/blog_migrate/57b34e091e5156fc92680321014e36a7.png)
![](https://i-blog.csdnimg.cn/blog_migrate/20bca40db97f20ea879fe753dfbb531a.png)
#!/usr/bin/python
#coding=utf-8
'''
Created on 2012-9-25
@author: linzuxin
'''
status = {}
def factorial(n):
'''
输入一个数字,求其阶乘。status是一个hash,用来存储中间结果,避免重复计算
@param n: 要求的数字
@return: n的阶乘
'''
if n == 0 or n == 1:
status[0] = 1
status[1] = 1
return 1
elif status.has_key(n):
return status[n]
else:
status[n] = factorial(n - 1) * n
return status[n]
print factorial(100)
#!/usr/bin/python
#coding=utf-8
'&#