N! Number of zeros |
Time limit 1000 ms |
Memory limit 65536 K |
|
Description |
Read N from the input and obtain n! The number of zeros at the end. |
Input |
The input has several rows. There is an integer m on the first line, indicating the number of the following numbers. Then there are m rows. Each row contains a definite positive integer N, 1 & lt; = N & lt; = 1000000000.
|
Output |
Output a row for each data N in the input row. The content is n! The number of zeros at the end.
|
Sample_input |
331001024
|
Sample_output |
024253
|
The nature of the basic theorem of prime numbers. The basic theorem of prime numbers: Each positive integer n greater than 1 can be uniquely written as the product of prime numbers, and the prime factors in the product are arranged in non-descending order, N = (P1 ^ A1) * (P2 ^ A2 )*..... * (Pk ^ AK ).
N! The power of prime p in prime Factorization of is: [N/P] + [N/P ^ 2] + [N/P ^ 3] + .........
Let's look at this question again and say n! There are several zeros in the end. Obviously we cannot calculate n !, So we need to find features.
For any positive integer, if the positive integer is decomposed by a factor, the 0 at the end of the positive integer must be divided into 2*5, so each 0 must correspond to a 5, but at the same time, two more are required. For N !, In factorization, the number of factor 2 is more than the number of Factor 5, so if there is a factor 5, it must correspond to n! If there is a zero value at the end, this question becomes "N! The number of factors 5 in the decomposition, so the above formula will be used.
The Code is as follows:
#include <stdio.h>#include <string.h>#include <math.h>int main(){int i,j,s,n;int cas,ans,t;scanf("%d",&cas);while(cas--){scanf("%d",&n);s=5;ans=0;t=n/5;while(t!=0){ans+=t;s*=5;t=n/s;}printf("%d\n",ans);}return 0;}
NEFU 118 n! Number of basic 0 arithmetic theorem followed by prime number Decomposition