       Re: discrete math, how many zeroes in 125!

• To: mathgroup at smc.vnet.net
• Subject: [mg13496] Re: discrete math, how many zeroes in 125!
• From: scottb (Scott Brown)
• Date: Fri, 31 Jul 1998 04:33:15 -0400
• Organization: Wolfram Research, Inc.
• References: <6pebvk\$i76@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```>trafh at AOL.com 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

I'm not sure if this solution was offered yet.
You want the number of trailing zeroes, I think, since you
referred to 2 and 5.

Here's a way to count the factors without atually factoring.
Does this get you what you need?

(* Assuming n Prime,
* the number of factors of n in M! is the number of multiples of n
* that are less than M, plus the number of multiples of n^2 that
* are less than M, plus (etc.), up to the number of multiples less
* than M of the largest power of n that is less than M.
*)
multiplesPreceding[ n_Integer?PrimeQ, M_Integer ] :=
Plus @@ Table[
Floor[ M/(n^k) ],
{ k, 1, Floor[Log[n,M]] }
];

------------------------------------------------------------------------
| Scott Brown        | "I may be speaking from Wolfram Research, Inc.,
| | scottb at wolfram.com | but that doesn't mean I'm speaking for them."
|
------------------------------------------------------------------------

```

• Prev by Date: problem with Needs[ ] command
• Next by Date: Reading a file
• Previous by thread: Re: discrete math, how many zeroes in 125!
• Next by thread: Re: discrete math, how many zeroes in 125!