n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)

n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)

ID:12177823

大小:43.00 KB

页数:13页

时间:2018-07-16

n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)_第1页
n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)_第2页
n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)_第3页
n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)_第4页
n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)_第5页
资源描述:

《n的阶乘高精度算法解析(n factorial high-precision algorithm analysis)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、n的阶乘高精度算法解析(Nfactorialhigh-precisionalgorithmanalysis)Inanfactorial,nisgreaterthan16nfactorialresultsalwaysoverflowlongplasticpreservation,forjustlearningCstudentsalwaysfeelverydifficult,soBaiduinthesearchboxtype"factorial"twocharactersinsearchresults,"Baiduenc

2、yclopedia"interpretation,openthepage,andturndown,sawa"highprecisionfactorial"noftheCcode:#include#defineN5000ittoholdlargernumber//modifyIntmain(void){Int,N,I,J,s,up,f[N]={0};Scanf("%d",&n);For(I=2,f[0]=1;I

3、10;Up=s/10;}For(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Ifyoudon'tfeelgoodenoughtounderstand,youcanchangetothefollowingcode,andyou'llprobablygetalittlebetter:#include#defineN5000ittoholdlargernumber//modifyIntmain(void){In

4、t,N,I,J,s,up,f[N]={0};Scanf("%d",&n);F[0]=1;For(I=2;I

5、(I=N-1;f[i]=0;i--);For(;I>=0;i--)printf(%d,f[i]);Printf("");Return0;}Whenwefirstcontactthiscode,willyoufeelveryhelpless?Don'tyouseewhyyoudothat?Here'smyunderstandingofthecode:Firstofall,inordertounderstandhowthisstringofcodeworks,thebestwayistofindanumbertota

6、kein,findagoodwhitepaper,writewell,drawapicture,from0to5.Inessence,justtake5withyou,because...0!*1=1!;1!*2=2!;2!*3=3!;3!*4=4!;4!*5=5!;But3!=6<10;4;=24isjustover10;taking5ismoreuniversal.Let'stalkaboutwhathappenedwhenwewereinn=5.Sincetheouterloopstartswithi=2,we

7、startwithi=2.Theinnerloopisfor(j=0,up=0;js=f[0]*2+0=1*2+0=2;F[j]=s%10;----->f[0]=2%10=2;Up=s/10;----->up=2/10=0;TwoJ=1:s=f[j]*i+up;----->s=f[1]*2+0=0*2+0=0;F[j]=s%10;----->f[1]=0%10=0;Up=s/10;----->up=0/10=0;Whenthejisgr

8、eaterthanorequalto2,thecaseisthesameas"2.",andtheresultis:f[0]=2;f[1]=0;f[2]=0...Two:i=31.j=0:s=f[j]*i+up;----->s=f[0]*3+0=2*3+0=6;F[j]=s%10;----->f[0]=6%10=6;Up=s/10;----->

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。