python处理大数字的方法


Posted in Python onMay 27, 2015

本文实例讲述了python处理大数字的方法。分享给大家供大家参考。具体实现方法如下:

def getFactorial(n):
  """returns the factorial of n"""
  if n == 0:
    return 1
  else:
    k = n * getFactorial(n-1)
    return k
for k in range(1, 70):
  print "factorial of", k,"=", getFactorial(k)

运行结果如下:

factorial of 1 = 1
factorial of 2 = 2
factorial of 3 = 6
factorial of 4 = 24
factorial of 5 = 120
factorial of 6 = 720
factorial of 7 = 5040
factorial of 8 = 40320
factorial of 9 = 362880
factorial of 10 = 3628800
factorial of 11 = 39916800
factorial of 12 = 479001600
factorial of 13 = 6227020800
factorial of 14 = 87178291200
factorial of 15 = 1307674368000
factorial of 16 = 20922789888000
factorial of 17 = 355687428096000
factorial of 18 = 6402373705728000
factorial of 19 = 121645100408832000
factorial of 20 = 2432902008176640000
factorial of 21 = 51090942171709440000
factorial of 22 = 1124000727777607680000
factorial of 23 = 25852016738884976640000
factorial of 24 = 620448401733239439360000
factorial of 25 = 15511210043330985984000000
factorial of 26 = 403291461126605635584000000
factorial of 27 = 10888869450418352160768000000
factorial of 28 = 304888344611713860501504000000
factorial of 29 = 8841761993739701954543616000000
factorial of 30 = 265252859812191058636308480000000
factorial of 31 = 8222838654177922817725562880000000
factorial of 32 = 263130836933693530167218012160000000
factorial of 33 = 8683317618811886495518194401280000000
factorial of 34 = 295232799039604140847618609643520000000
factorial of 35 = 10333147966386144929666651337523200000000
factorial of 36 = 371993326789901217467999448150835200000000
factorial of 37 = 13763753091226345046315979581580902400000000
factorial of 38 = 523022617466601111760007224100074291200000000
factorial of 39 = 20397882081197443358640281739902897356800000000
factorial of 40 = 815915283247897734345611269596115894272000000000
factorial of 41 = 33452526613163807108170062053440751665152000000000
factorial of 42 = 1405006117752879898543142606244511569936384000000000
factorial of 43 = 60415263063373835637355132068513997507264512000000000
factorial of 44 = 2658271574788448768043625811014615890319638528000000000
factorial of 45 = 119622220865480194561963161495657715064383733760000000000
factorial of 46 = 5502622159812088949850305428800254892961651752960000000000
factorial of 47 = 258623241511168180642964355153611979969197632389120000000000
factorial of 48 = 12413915592536072670862289047373375038521486354677760000000000
factorial of 49 = 608281864034267560872252163321295376887552831379210240000000000
factorial of 50 = 30414093201713378043612608166064768844377641568960512000000000000
factorial of 51 = 1551118753287382280224243016469303211063259720016986112000000000000
factorial of 52 = 80658175170943878571660636856403766975289505440883277824000000000000
factorial of 53 = 4274883284060025564298013753389399649690343788366813724672000000000000
factorial of 54 = 230843697339241380472092742683027581083278564571807941132288000000000000
factorial of 55 = 12696403353658275925965100847566516959580321051449436762275840000000000000
factorial of 56 = 710998587804863451854045647463724949736497978881168458687447040000000000000
factorial of 57 = 40526919504877216755680601905432322134980384796226602145184481280000000000000
factorial of 58 = 2350561331282878571829474910515074683828862318181142924420699914240000000000000
factorial of 59 = 138683118545689835737939019720389406345902876772687432540821294940160000000000000
factorial of 60 = 8320987112741390144276341183223364380754172606361245952449277696409600000000000000
factorial of 61 = 507580213877224798800856812176625227226004528988036003099405939480985600000000000000
factorial of 62 = 31469973260387937525653122354950764088012280797258232192163168247821107200000000000000
factorial of 63 = 1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000
factorial of 64 = 126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000
factorial of 65 = 8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000
factorial of 66 = 544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000
factorial of 67 = 36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000
factorial of 68 = 2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000
factorial of 69 = 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000

希望本文所述对大家的Python程序设计有所帮助。

Python 相关文章推荐
python实现从网络下载文件并获得文件大小及类型的方法
Apr 28 Python
简单介绍Python中用于求最小值的min()方法
May 15 Python
python 根据pid杀死相应进程的方法
Jan 16 Python
python实现下载整个ftp目录的方法
Jan 17 Python
Python爬虫实例爬取网站搞笑段子
Nov 08 Python
Python中defaultdict与lambda表达式用法实例小结
Apr 09 Python
python Tkinter的图片刷新实例
Jun 14 Python
python networkx 包绘制复杂网络关系图的实现
Jul 10 Python
详解django实现自定义manage命令的扩展
Aug 13 Python
tensorflow指定GPU与动态分配GPU memory设置
Feb 03 Python
python GUI库图形界面开发之PyQt5信号与槽基础使用方法与实例
Mar 06 Python
如何创建一个Flask项目并进行简单配置
Nov 18 Python
python类继承用法实例分析
May 27 #Python
python显示生日是星期几的方法
May 27 #Python
python中zip和unzip数据的方法
May 27 #Python
Python pickle模块用法实例分析
May 27 #Python
Python创建模块及模块导入的方法
May 27 #Python
Python类的用法实例浅析
May 27 #Python
Python socket编程实例详解
May 27 #Python
You might like
PHP与MySQL开发的8个技巧小结
2010/12/17 PHP
PHP字符串的编码问题的详细介绍
2013/04/27 PHP
基于php设计模式中单例模式的应用分析
2013/05/15 PHP
去掉destoon资讯内容页keywords关键字自带的文章标题的方法
2014/08/21 PHP
php自动给网址加上链接的方法
2015/06/02 PHP
WordPress中编写自定义存储字段的相关PHP函数解析
2015/12/25 PHP
深入理解PHP 数组之count 函数
2016/06/13 PHP
php+Memcached实现简单留言板功能示例
2017/02/15 PHP
php获取ajax的headers方法与内容实例
2017/12/27 PHP
通过PHP设置BugFree获取邮箱通知
2019/04/25 PHP
JavaScript 组件之旅(四):测试 JavaScript 组件
2009/10/28 Javascript
判断iframe是否加载完成的完美方法
2010/01/07 Javascript
jquery multiSelect 多选下拉框
2010/07/09 Javascript
用js实现输入提示(自动完成)的实例代码
2013/06/14 Javascript
浅析Cookie中的Path与domain
2013/12/18 Javascript
get(0).tagName获得作用标签示例代码
2014/10/08 Javascript
JavaScript+CSS实现的可折叠二级菜单实例
2016/02/29 Javascript
JS实现图片延迟加载并淡入淡出效果的简单方法
2016/08/25 Javascript
AngularJS实现ajax请求的方法
2016/11/22 Javascript
详解浏览器渲染页面过程
2017/02/09 Javascript
webpack使用 babel-loader 转换 ES6代码示例
2017/08/21 Javascript
在Debian(Raspberry Pi)树莓派上安装NodeJS的教程详解
2017/09/19 NodeJs
vue代理和跨域问题的解决
2018/07/18 Javascript
微信小程序实现滚动加载更多的代码
2019/12/06 Javascript
python转换摩斯密码示例
2014/02/16 Python
在Python中使用matplotlib模块绘制数据图的示例
2015/05/04 Python
由浅入深讲解python中的yield与generator
2017/04/05 Python
python决策树之CART分类回归树详解
2017/12/20 Python
Python迭代器定义与简单用法分析
2018/04/30 Python
修改默认的pip版本为对应python2.7的方法
2018/11/06 Python
Python高级编程之继承问题详解(super与mro)
2019/11/19 Python
Python JSON编解码方式原理详解
2020/01/20 Python
大学生职业生涯规划书范文
2014/01/14 职场文书
2014年减负工作总结
2014/12/10 职场文书
MySQL Router实现MySQL的读写分离的方法
2021/05/27 MySQL
CSS浮动引起的高度塌陷问题
2022/08/05 HTML / CSS