Not a multiple of 5, no matter which one is multiplied, the result of a single digit being 0 is impossible.
25*4 = 100, can generate two 0, the same is true (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 ......
#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;}
Running result: 253
Analysis:
Number of multiples of 5: 1024/5 = 204
The number is a multiple of 25: 1024/25 = 40
Number of multiples of 125: 1024/125 = 8
Which is a multiple of 625: 1024/625 = 1
Therefore, the result is 253.