N! Zero in

Source: Internet
Author: User

Input:

Enter several rows. Each row has an integer T, which is the number of test data groups, followed by T rows. Each row contains a definite positive integer N, 1 equal to = 1 000 000 000.

Output:

Output a row for each data N in the input row. The content is n! Number of 0 at the end

Analysis:

The so-called "Number of 0" refers to the total number of 10 factors, and 10 can represent the product of 2 and 5. Suppose M = n !, Then the number of 2 factors in m must be greater than the number of 5 factors. Therefore, you only need to find the number of 5 factors in M.

Since M = N * (n-1) * (n-2) * · * 1, you can use n divided by 5 to get 1 ~ Number of groups in n that can be divided by 5. However, this is not the number of all factors 5, because 1 ~ Some trees in N can be divided by 5 several times. Therefore, you must divide the number by 5 to get 1 ~ Number of groups in n that can be divided by 25. Then, divide the number by 125 and cyclically until the number is 0.

So calculate n! The formula for the number of 0 at the end is a = [N/(5*5 · * 5)]

# Include <stdio. h> void main () {int N; int I = 0; scanf ("% d", & N); int K; For (k = N; k> 0; k = -- N) {While (K % 5 = 0) {++ I; k = K/5;} printf ("the number is = % d ", I );}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.