0 of factorial Time limit:3000MS | memory limit:65535KB Difficulty:3
Description
Calculate n! In decimal format.
Input
Enter an integer N in the first line to indicate the number of groups of test data (1 <= n <= 100)
Each group of test data occupies one row, with only one integer m (0 <= m <= 10000000)
Output
Number of the last 0 in the decimal number of the factorial output M
For example, 5! = 120 then the number of the last 0 is 1
Sample Input
63601001024234568735373
Sample output
0142425358612183837
resolution: considering that 0 can only be obtained from" 2*5 ", and a" 5 "can easily match" 2, (because the number of "2" is much greater than the number of "5"), you only need to calculate the number of "5". Here, we take 720 as an example, to calculate the number of "5. That is, sum = 0; 720/5 = 144; sum + = 144; 144/5 = 28; sum + = 28; 28/5 = 5; sum + = 5; 5/5 = 1; sum + = 1; the calculation here is equivalent to 1 5 ^ 4, 5-1 5 ^ 3, 28-5-1 5 ^ 720-28-5-1 5 in 2,144.
the Code is as follows:
# include
int main () {int n, m, sum; scanf ("% d", & N); While (n --) {sum = 0; scanf ("% d", & M); While (m) {M/= 5; sum + = m;} printf ("% d \ n ", sum) ;}