The first thing you should notice is that every instance of a multiple of 10 in the factorial expansion will yield a trailing zero. Next, notice that multiples of 5 and 2 will yield trailing zeroes, including the same yielded by the multiples of 10.

In the factorization of 1000000, there are far more 2s than there are 5s. Thus, in order to count the number of trailing zeroes, we need only count the number of 5s that occur as factors.

This can be done simply with:

floor(1000000/5) + floor(1000000/5^2) + floor(1000000/5^3) + floor(1000000/5^4) + floor(1000000/5^5) + floor(1000000/5^6) + floor(1000000/5^7) + floor(1000000/5^8)

(And since 5^9 = 1953125 > 1000000, no further terms are needed past 5^8.)

The result:

200000 + 40000 + 8000 + 1600 + 320 + 64 + 12 + 2 =

**249998**Two other related problems from Project Euler can be found

here and

here.