I have seen this question several times before, and I don't remember where it was.
1024 can be counted as N
There are two solutions:
I. Using Big integer operations is also a "brute force solution. However, the length of the possible solution is the next hop. This method is not advisable.
2. It is not difficult to find out using mathematical theories:
1. The number of result 0 is irrelevant to the number smaller than 5 in N. Not a multiple of 5, no matter which one is multiplied, the result of a single digit being 0 is impossible.
The number of even numbers within n must be greater than 5 (5 and even numbers can be multiplied to increase the number of last 0 ).
So there are a = N/5;
2. Let's take a look at 25. Is this special? 25*4 = 100, two zeros can be generated. Why? Because 25 = 5*5, the number of excess zeros that can be generated is related to the number of contained factors 5.
25*4 = 100, there are two 0,100, no matter the number is multiplied by any number that is not a factor of 10, it is impossible to generate an extra number of two 0. Likewise (75 = 25*3 = 5*5*3) * 4 = 300; (125 = 5*5*5) * 8 = 1000;
That is, the number of factors 5 in a number can be multiplied by enough even numbers to generate the last 0 of the same number.
Summary: The number of the last 0 in the factorial of N is: N/5 + N/25 + N/125 ......
Computing TestProgram:
# Include <stdio. h> int zero_count (int n); int main (INT argc, char * argv []) {printf ("zero_count is % d... \ n ", zero_count (1024); Return 0;} int zero_count (int n) {int COUNT = 0; while (n> 0) {n = N/5; count + = N;} return count ;}