Re: discrete math, how many zeroes in 125!
- To: mathgroup at smc.vnet.net
- Subject: [mg13518] Re: [mg13418] discrete math, how many zeroes in 125!
- From: Wouter Meeussen <eu000949 at pophost.eunet.be>
- Date: Fri, 31 Jul 1998 04:33:31 -0400
- Sender: owner-wri-mathgroup at wolfram.com
At 03:33 23-07-98 -0400, Timothy Anderson wrote: >how can I solve this problem by counting the factors of 2 and 5 without >doing each factor individually? thanks for any real quick help! Tim > > Equivalently to Ken Levasseur <Kenneth_Levasseur at uml.edu> from UMass Lowell Mathematical Sciences ref: [mg13440] Re: [mg13418] discrete math, how many zeroes in 125! and with due thanks to Richard Schroeppel who showed me this : quote: " the exact power of p that divides ( n! ) is " (n-Sum of the digits of the base p representation of n)/(p-1) " end_quote note that n_factorial need not be computed, giving a small but significant (;-) advantage for moderate to large n. try for instance : In[1]:=n=2345; Length[Last[Split[IntegerDigits[n!]]]]//Timing Min[(n-Plus@@IntegerDigits[n,#])/(#-1) &/@ {2,5}]//Timing Out[1]= {1.92 Second, 583} Out[2]= {0.05 Second, 583} Dr. Wouter L. J. MEEUSSEN w.meeussen.vdmcc at vandemoortele.be eu000949 at pophost.eunet.be