Count the number of 0s on the right-hand side of the factorial

Count the number of 0s on the right-hand side of the factorial

When \(n\) is large, computing \(n!\) becomes very difficult. Under this premise, if you want to calculate how many \(0\) there are on the right end of \(n!\) , you need to use some mathematical skills.

Any natural number greater than \(1\) can be written in the form of the product of prime numbers. In prime numbers, only \(2 * 5\) can get a \(0\) , so we need to calculate \(n!\) After decomposing the prime factors, the number of \(2\) and the number of \(5\) . Obviously the number of \(2\) is more than the number of \(5\) , so just calculate how many factors are \(5\) at the end .

\(f(n)=[\frac{n}{5}]+[\frac{n}{25}]+[\frac{n}{125}]+[\frac{n}{625}]+...\)

\(5,10,15,20...​\) These can contribute one \(5​\) , while \(25,50...​\) can contribute two \(5​\) . The number that can contribute two \(5​\) has already been calculated once in the first calculation, so this calculation does not conflict.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324582137&siteId=291194637