HDU 1124 factorial (factorial suffix 0)

Source: Internet
Author: User

Test instructions: Give a number n, return its factorial result suffix has several 0.

Ideas:

First, the decimal quality factor is decomposed to 2*5=10. The n! mass factor decomposition, then decomposition, which should contain a min (2 number, 5 number) suffix 0.

Why do you say that? For example N=15, then {1 2 3 4 5 6 7 8 9, then you can generate 2 of the number has {2,4,6,8,10,12,14}, can produce 5 of only {5,10,15} , only 2 times 5 in prime numbers to Form 10, because only 2 is an even number of primes!!! Then min (2 numbers, 5 numbers) determines the number of 10 that can be generated, and it determines the number of 0 produced.

Want to decompose [1,n] one by one to take the number of statistics 5? No. Assuming n=15, the N/5 get 3, then [1,15] 3 is a multiple of 5 is {5,10,15}, only a multiple of 5 to produce a factor of 5, then count+=3. Then, these 3 numbers may still be large, and may continue to be removed by 5 (for example, 25 can be removed two times). However {5,10,15} has been replaced by {A-i}, this sequence must be a continuous natural number, because all is less than 5, that must not be able to produce another 5. What if N/5 is greater than 5? Then [1,n] in multiples of 5 will certainly become [1,N/5], but also a factorial form, continue to use the above method to continue to remove all 5, until the result of N/5/5/5 ... is less than 5. The number after each N/5 is the result of count.

1#include <bits/stdc++.h>2 #defineLL Long Long3 using namespacestd;4 intF (unsignedintN)5 {6     if(N <5) {7         return 0;8     }9     returnN/5+ F (N/5);Ten } One  A intMain () - { -     //freopen ("Input.txt", "R", stdin); theUnsignedintT, A; -Cin>>T; -      while(t--) -     { +scanf"%d",&a); -printf"%d\n", F (a)); +     } A  at     return 0; -}
AC Code

HDU 1124 factorial (factorial suffix 0)

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.