What decimal digit occurs most often in the sequence of factorials from 77777! to 77877! inclusive?
This can be solved by logic. You do not need to compute any factorials.
Zero.
The number of trailing zeros in N! is given by the sum of [[N//5^i]]
where i goes from 0 to [[log(N,5)]],
and log(N,5 is log of N base 5, and
[[]] is greatest integer.
So 77777! ends with 19440 trailing zeros
A little help from a full precision calculator shows that the total number of digits of 77777! is 346621. So 5.6% of the digits are trailing zeros.
So it is likely that each of factorials of these 5 digit numbers is composed of roughly 15% zeros, with the frequency of each of the other nine digits being roughly 9.4%.
---------
def trail0s(n):
""" how many zeros at the end of n Factorial? """
import math
zeros = 0
hipower = int(math.log(n,5))
for p in range(1, hipower + 1):
zeros += n // 5**p
return zeros
|
Posted by Larry
on 2024-05-29 11:18:21 |