Problem of the Day
A new programming or logic puzzle every Mon-Fri

Trailing Zeroes

This one is a bit mathy by nature. The goal is to find the number of trailing zeroes in X!. 5! = 120 so it has 1 trailing zero. Can you solve for 100!? If you choose to not go the programmatic route, what's the mathematical proof for this problem?

Update: The solution for Three Primes has been posted to the comments.

Permalink: http://problemotd.com/problem/trailing-zeroes/

Comments:

  • David - 9 years, 9 months ago

    You get an excess of factors of 2 relative to adding factors of 5, so every multiple of 5 will add a trailing zero. Additionally, every multiple of 25 will add an additional trailing zero. Based on this, one can simply count the multiples of 5 and 25 in [1,100]. For larger values of X, one must count multiples of each subsequent exponent of 5 less than X.
    For 100! you get:

      5 10 15 20 25
    30 35 40 45 50
    55 60 65 70 75
    80 85 90 95 100
    
    20 multiples of 5 + 4 multiples of 25 gives a prediction of 24 zeroes.
    

    From wolframalpha you can count that there are in fact 24 zeroes.

    reply permalink

Content curated by @MaxBurstein