Factorial question: number of trailing zeroes in 125! How many zeros are after the last nonzero digit of 125! ?

The answer is 31, but how do you solve it?
Well, we know that to have a zero at the end then $10$ must be a factor, which means $5$ and $2$ must be factors. However, every other factor is even, so there are far more factors of $2$ than $5$ - As such, we have to count the number of factors divisible by $5$. The number of factors divisible by $5$ less than or equal to $125$ is $25$ (we just do $\frac{125}{5}$), so the answer appears to be $25$, but then we remember that $25 = 5\cdot5$, so we must count double for each factor divisible by $25$, of which there are $5$; accordingly, our new answer is $30$. BUT WAIT... $125 = 5^3$, so we have to count it too, giving us a final answer of $31$
I just count them.

125! = 188267717688892609974376770249160085759540364871492425887598231508353156331613598866882932889495923133646405445930057740630161919341380597818883457558547055524326375565007131770880000000000000000000000000000000

Have a Apple computer? Compute the value yourself. Below is the applescript. Paste into the Script Editor application and click on the "Run the Script" button.

on ids(digits as text)
    if digits is "" or digits is not "0" and digits starts with "0" then error "bad integer " &amp; digits
    set x to (id of digits) as list
    repeat with digit in x
        if digit &lt; 48 or digit &gt; 57 then error "bad integer"
    end repeat
    return x
end ids

on add(x as text, y as text)
    set {a, b, n, carry} to {ids(x), ids(y), (length of x) - (length of y), 0}
    if n &lt; 0 then set {a, b, n} to {b, a, -n}
    repeat with i from length of a to 1 by -1
        set {carry, sum, j} to {0, carry + (item i of a), i - n}
        if j &gt; 0 then set sum to sum + (item j of b) - 48
        if sum &gt; 57 then set {carry, sum} to {1, sum - 10}
        set item i of a to sum
    end repeat
    if carry &gt; 0 then set beginning of a to carry + 48
    return character id a
end add

on multiply(x as text, y as text)
    set {a, b, c, sum} to {ids(x), ids(y), {}, "0"}
    repeat with m from length of b to 1 by -1
        set multiplier to (item m of b) - 48
        if multiplier is not 0 and x is not "0" then
            set carry to 0
            repeat with i from length of a to 1 by -1
                set product to carry + ((item i of a) - 48) * multiplier
                set carry to product div 10
                set beginning of c to product mod 10 + 48
            end repeat
            if carry &gt; 0 then set beginning of c to carry + 48
            set sum to add(sum, character id c)
        end if
        set end of c to 48
        set c to items (m - (length of b) - 1) thru end of c
    end repeat
    return sum
 end multiply

 set x to 1
 repeat with y from 1 to 125
    set x to multiply(x, y)
 end repeat