Lovefilm, yes or no?
Paul Makepeace
paulm at paulm.com
Wed Apr 14 19:12:52 BST 2010
On Wed, Apr 14, 2010 at 10:29, Abigail <abigail at abigail.be> wrote:
> On Wed, Apr 14, 2010 at 09:47:14AM -0700, David Alban wrote:
>> On Wed, Apr 14, 2010 at 9:36 AM, Merijn Broeren <merijnb at iloquent.com> wrote:
>> > Does 128! end in a zero? If so, how many?
>>
>> i would think that any factorial N! would end in zero if N > 9. but i
>> have no idea how many zeroes are at the end of <128!>.
>
>
> 5! multiples 2 and 5.
>
> The trick is to count the number of factors of 5.
It's worth noting explicitly that those factors of 5 work to create
trailing zeros because there is an excess of spare factors of 2 to
make 2*5=10.
> floor (128 / 5) + floor (128 / 25) + floor (128 / 125) = 25 + 5 + 1 = 31.
>
>
> $ perl -E'$,="*";say 1..128'|bc|perl -0ne's/\D+//g;print/0+$/g'|wc -c
> 31
Nice. Mathematica,
Sum[Floor[128/5^k], {k, Floor[Log[5, 128]]}]
31
Log[5, 128] is the log base 5 of 128, i.e. the number you need to
raise 5 to to get 128 (=3.01...). The integer component of that
(Floor[]) gives you then the number of factors of five in 128 (=3).
The bit in the Sum[] is an iterator (k=1..3) creating a list {25, 5,
1} whose sum is 31.
Paul
> Abigail
>
More information about the london.pm
mailing list