#include <stdio.h> #include <stdlib.h>int main () { int t,n; while (scanf ("%d", &t)!=eof) { int i; for (i=0;i<t;i++) { int sum=0; scanf ("%d", &n); while (N) { n/=5; sum+=n; } printf ("%d\n", sum); } } return 0;}
If there are 4 numbers, 5*1 5*5*5 5*5*3 5*9
1. Become 5*n1 5*n2 5*n3 5*n4 There are 4 numbers is a multiple of 5
2. Become 5*n1 5*5*n5 5*5*n6 5*n4 There are 2 numbers is a multiple of 25
3. Become 5*n1 5*5*5 5*5*n6 5*n4 There are 1 numbers is a multiple of 125
The above is to avoid repetition, only 1 layers at a time (one-off)
The number of 5 per addition is actually the number on the right
Should be the theorem of number theory: for factorial n! , the number of 1 to N is a multiple of 5 for a given N,N/5
Also for n/25,n/125
The aim is to n/5+n/25+n/125 ...
If there is a 0, the sum is
Right
while (N) { sum+=n/5; N/=5;}
Interpretation: Multiple additions, and each time to see a number divided by 5,sum overlay
N/5+n/25+n/125 ... can be seen as N/5+N1/5+N2/5
N1=n/5,n2=n1/5
Loop body: Each value is a number divided by 5, and the number of each number compared to the previous count except 5
while (N) { sum+=n/5; n/=5; }
For a logical relationship:
A number if it is a multiple of 25, then he must be a multiple of 5, on the contrary, it is not right, so this is the pillar he can layer
POJ 1401---ask N! The number of the end 0, 2 of the number must be more than 5, observed, 0 of the production is 2*5, to find this factorial line 5 of the number can be