Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: discrete math, how many zeroes in 125!

  • To: mathgroup at
  • Subject: [mg13518] Re: [mg13418] discrete math, how many zeroes in 125!
  • From: Wouter Meeussen <eu000949 at>
  • Date: Fri, 31 Jul 1998 04:33:31 -0400
  • Sender: owner-wri-mathgroup at

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>
  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 :

Min[(n-Plus@@IntegerDigits[n,#])/(#-1)  &/@ {2,5}]//Timing

{1.92 Second, 583}
{0.05 Second, 583}
Dr. Wouter L. J. MEEUSSEN
w.meeussen.vdmcc at
eu000949 at

  • 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?