首页 > 编程知识 正文

1的阶乘加到99的阶乘个位数,求整数n的阶乘的算法java

时间:2023-05-05 06:20:25 阅读:186493 作者:347

big number http://www.Sina.com/1000 ms http://www.Sina.com/65536 k http://www.Sina.com/21661358 www.Sina.com/6888

inmanyapplicationsverylargeintegersnumbersarerequired.someoftheseapplicationsareusingkeysforsecuretransmionofdata, encryytionsforsecuretransmisionofdata etc.inthisproblemyouaregivenanumber,youhavetodeterminethenumberofdigitsinthefactorinthefactoriorianttttorionttorion

inputconsistsofseverallinesofintegernumbers.thefirstlinecontainsanintegern,whichisthenumberofcasestobested,Followedbyn

theoutputcontainsthenumberofdigitsinthefactorialoftheintegersappearingintheinput.sample input

21020样本输出

719源

Dhaka 2002题意:计算n的阶乘的位数1 # include stdio.H2 # include math.h 34 intn; 5 const double e=2.7182818284590452354,pi=3.141592653589793239; 6doublef(inta )8{9returnlog10 ) sqrt )2*pi*a ) ) a*log10 ) a/e ); 10 ) 1112intmain () 13 ) 14intcas,ans; 15双精度I,s; 1617Scanf('%d ',cas ); 819while(CAS----) 20(21Scanf ),n ); 2if(n100000 ) 23 ) 24for ) s=0,i=1; i=n; I ) 25s=log10(I; 26 ) 27elses=f(n; 28ans=(int ) s; 29if(ans=s ) 30 ans; 1332printf('%d/n ',ans ); 33 ) 34return0; 35 }

注: Stirling公式介绍: lim(n) (n/e ) n *(2n )/n!=1即n大时,n! (2n ) ) n/e ) )与n的值非常接近的是Stirling公式。 官方的证明令a(n )=n! /[n^(n1/2 ) e^(-n ) ]中,当a(n )/a ) n1 )=) n1 ) ^(n 3/2 ) * (n1 ) *e )=) n1 ) ^ ) n1 e时)1 1/n ) ^1/21即lim(n) a ) n )/a ) n1 )=1,因此lim(n) a ) n )存在a=Lim )/[n^(n1/2 ) 呃!/(2n-1 (! 呃! ]^2/(2n1)/2=lim(n) ) (2n )! 呃!/(2n-1 (! 呃! ]^2/(2n1)=lim(n) (2n )! 呃! (2n )! 呃!/(2n (! ]^2/(2n1 )=lim(n)2^ ) 4n ) ((n! ()2/(2n )! ]^2/(2n1)=lim(n)e^(-n ) ) a*n^ ) n1/2 ) e^(-n ) ) a*(2n ) ^(2n 1/2) ) e^ ) (-289 ) ) 652 ^2/(2n1 )=lim(n)2^ ) 4n ) a^2*2^ ) (-4n-1 ) n/) 2n1)=A^2/4所以a=(2) lim ) n /[n^(n1/2 ) e^(-n ) ]=(2)即lim(n) ) 2n ) n*e^(-n )/n!=1公式的意思: Stirling公式的意思是:当n足够大时为n! 计算非常困难。 关于n有很多! 来定义自定义外观。 但是,我不能很好地估计阶乘的结果。 特别是n大的话,误差会变得非常大。 但利用Stirling公式可以将阶乘转化为幂函数,从而更好地估计阶乘的结果。 而且,n越大,就越能准确地估计。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。