tags:

views:

134

answers:

2

I have a problem and can't solve it alone. My teacher gives me one logic task today, and i'm sure you can help me.

How can I count the number of zeroes at the end of factorial(41). (on paper) I understand that it has nothing to do with programing, but I'm sure programers can help me.

Thanks in advance.

+4  A: 
floor(n/5) + floor(n/25) + floor(n/125)+.......+floor(n/5^n)

in your case n = 41


See comments below

Sorantis
Surely you mean floor()?
Simon Nickerson
round here shows that only integer part of each expression should be considered (yes, floor)
Sorantis
@Sorantis: `round(9/5) = 2` and `floor(9/5) = 1`
N 1.1
see comment above
Sorantis
n=41, not 9 ... (9/5) was just an example for demonstrating floor vs. round
tanascius
The result IS 9
Sparr
ok, i've understand all! thanks
Syom
+7  A: 

If you know the trick, you don't even need paper. The number of zeros at the end is how many times it's divisible by 10 . . . in terms of the prime factorization, this is the minimum of the number of times it's divisible by 5 and the number of times it's divisible by 2 (since we need one factor of both 2 and 5 to make a factor of 10). But with factorial we're including every factor less than or equal to 41, so we'll get a lot more factors of 2 than factors of 5. So we only need to worry about how many factors of 5 there are.

So count the numbers that are less than or equal to 41 and divisible by 5: 5,10,15,20,25,30,35,40

There's 8 of them, but don't forget that 25 gives us an extra factor of 5, since it's divisible by 5 twice. So 9 factors of 5 (and thus 9 factors of 10) in all.

Tim Goodman
+1 This is *so* much clearer than the Sorantis thread.
Jon-Eric
Good explanation. I just wrote the result of it in one formula. I thought it was pretty obvious. My bad
Sorantis
@Syom, it mean that you didn't really understand the question you were asked. And coming back to your question it means that there's 49 digits more, written in scientific format.
Sorantis
@Syom: That's scientific notation . . . it means 3.345... times 10 to the 49th power. But often with scientific notation some of the digits are truncated. In this case the exact answer is 33452526613163807108170062053440751665152000000000, or in other words 3.3452526613163807108170062053440751665152 x 10^49 [Source: WolframAlpha -- just type in 41! (the ! means factorial)]
Tim Goodman
However, don't go turning that answer in . . . the point of the problem is surely to understand the factorization so you don't *have* to actually compute 41!
Tim Goodman
@Tim Goodman you are really goodman:))))))))))) thanks
Syom
@Syom: You're welcome.
Tim Goodman
@Syom: I'm a little hesitant to post my contact info on a public forum, and unfortunately StackOverflow doesn't currently support private messaging. I'll keep replying to comments here if you want to discuss further . . . or if you have a followup question that's pretty far from this one perhaps it deserves its own topic.
Tim Goodman