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中函数的参数传递与可变长参数介绍
Jun 30 Python
详谈Python2.6和Python3.0中对除法操作的异同
Apr 28 Python
Python学习入门之区块链详解
Jul 25 Python
python3使用SMTP发送简单文本邮件
Jun 19 Python
老生常谈python中的重载
Nov 11 Python
使用python3构建文件传输的方法
Feb 13 Python
Python操作Jira库常用方法解析
Apr 10 Python
Keras SGD 随机梯度下降优化器参数设置方式
Jun 19 Python
python两个list[]相加的实现方法
Sep 23 Python
python 进制转换 int、bin、oct、hex的原理
Jan 13 Python
聊聊python在linux下与windows下导入模块的区别说明
Mar 03 Python
pytorch 实现在测试的时候启用dropout
May 27 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 图片上添加透明度渐变的效果
2009/06/29 PHP
PHP图片等比例缩放生成缩略图函数分享
2014/06/10 PHP
PHP中ID设置自增后不连续的原因分析及解决办法
2016/08/21 PHP
Laravel5.7 Eloquent ORM快速入门详解
2019/04/12 PHP
javascript URL编码和解码使用说明
2010/04/12 Javascript
Javascript中的isNaN函数使用说明
2011/11/10 Javascript
使用按钮控制以何种方式打开新窗口的属性介绍
2012/12/17 Javascript
Jquery 返回json数据在IE浏览器中提示下载的问题
2014/05/18 Javascript
javascript中$(function() {});写与不写有哪些区别
2015/08/10 Javascript
js精美的幻灯片画集特效代码分享
2015/08/29 Javascript
jQuery+canvas实现简单的球体斜抛及颜色动态变换效果
2016/01/28 Javascript
a标签跳转到指定div,jquery添加和移除class属性的实现方法
2016/10/10 Javascript
angular仿支付宝密码框输入效果
2017/03/25 Javascript
新手如何快速理解js异步编程
2019/06/24 Javascript
简单了解Vue + ElementUI后台管理模板
2020/04/07 Javascript
vant组件中 dialog的确认按钮的回调事件操作
2020/11/04 Javascript
[01:04:05]VG vs Newbee 2018国际邀请赛小组赛BO2 第一场 8.17
2018/08/20 DOTA
在Django框架中伪造捕捉到的URLconf值的方法
2015/07/18 Python
Python设计模式之抽象工厂模式
2016/08/25 Python
python 运用Django 开发后台接口的实例
2018/12/11 Python
python画柱状图--不同颜色并显示数值的方法
2018/12/13 Python
解决python super()调用多重继承函数的问题
2019/06/26 Python
通过python改变图片特定区域的颜色详解
2019/07/15 Python
python中树与树的表示知识点总结
2019/09/14 Python
浅谈Django QuerySet对象(模型.objects)的常用方法
2020/03/28 Python
python3读取autocad图形文件.py实例
2020/06/05 Python
全球知名旅游社区法国站点:TripAdvisor法国
2016/08/03 全球购物
俄罗斯设计师家具购物网站:The Furnish
2019/12/01 全球购物
4s店市场专员岗位职责
2014/04/09 职场文书
爱国主义教育演讲稿
2014/08/26 职场文书
师范生见习报告
2014/10/31 职场文书
2014年学生会主席工作总结
2014/11/07 职场文书
2015年监理个人工作总结
2015/05/23 职场文书
幼儿园开学温馨提示
2015/07/15 职场文书
中秋节主题班会
2015/08/14 职场文书
k-means & DBSCAN 总结
2021/04/27 Python