Tim Peters wrote: > [Dick Moores, computes 100 factorial as > > 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 > > but worries about all the trailing zeros] > >> <BLUSH> Yes, I'm sure you are. I'd forgotten about all those factors >> of 100! that end in zero (10, 20, 30, ..., 100). > > And others, like 2 and 5 whose product is 10, or 4 and 25 whose product is > 100. > > For a fun :-) exercise, prove that the number of trailing zeroes in n! > is the sum, from i = 1 to infinity, of n // 5**i (of course as soon as > you reach a value of i such that n < 5**i, the quotient is 0 at that i > and forever after). > > In this case, > > 100 // 5 + 100 // 25 + 100 // 125 + ... = > > 20 + 4 + 0 + ... = > > 24
you should do that with floating-point, so that the quotient never get's zero and the "i=1 to infinity" makes sense. This way you (might) get 25 which is correct; not 24. but i'm just guessing - i have no way to prove it ;-) _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
