Factorial Trailing Zeroes
a bit optimizing as I saw lots of answers did not figure this out:
better than rank 1
What I don't understand about any of these solutions is why aren't we counting 10, 20, 30, 40, etc, which all add a trailing zero?
10! has 2 trailing zeroes, one for the 2*5 and one for the 10. Why are we only concerned with 2s and 5s?
Yes, you are correct. I misread your code initially.
Usually recursion is slower. Could you please explain your findings?
Hi, prime_tang. Your code is more concise :-)
very nice and simple solution!
Since 10 = 2*5, and there are always more 2's than 5's, we only need to count the number of 5 factor in n!
it will only count 5 whose number is equal to trailing zeros.
it should be floor(n/5) + floor(n/25) + floor(n/125) + ....
because the int overflow,in the last time i=i*5,the result should be larger than the up-limit int type and then becomes a small number,so your amount of the zeros will be more than the ans
No one has replied
here is a more detailed explanation
Oh,sokka.Thanks for your reply.
The speed is average, u can run it urself to see
the same but iterative:
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.