Factorial problem in DSA learning series

Hi All,

Can anyone please help me to understand this problem. I am a beginner and i solved 3 first problems in DSA learning series. After i checked this problem i couldn’t even understand it… and i saw submissions… most of them wrote like dividing by 5 but i didn’t even understand why they are doing like this.
problem link: CodeChef: Practical coding for everyone

Thanks in advance.

Actually finding the trailing zeroes in the factorial of number is same as the number of multiple of 10s the number has in the factorial
for eg: 5!=2 * 2 * 2 * 3 * 5 so trailing zeroes is 1
Now,if you observe properly you will see that the number of factors of 10 is determined by the number of 5s in the prime factorisation as the number of 5 are always less than 2s…So our task is reduced to counting number of 5s in the prime factors of n to find the trailing zeroes.So you just need to find the floor of the number/5 i.e. floor(n/5). But in numbers like 25 and 625 there is this extra 5 which you have to take care as well.

Thank you very much for your explanation. but I didn’t even know about prime factorization. could you please help me to explain briefly if you don’t mind. Thank you once again.