MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: discrete math, how many zeroes in 125!


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



  • Prev by Date: Re: Help please: Summing a list
  • Next by Date: displaying animation grahps in one place
  • Previous by thread: Re: discrete math, how many zeroes in 125!
  • Next by thread: n32 version of libML.a for IRIX?