51nod_1003 factorial 0 of the number (5 in the n!, number theory)

Source: Internet
Author: User

Test instructions

How many 0 are behind the factorial of n? The factorial of 6 = 1*2*3*4*5*6 = 720,720 is followed by a 0. Input
A number n (1 <= n <= 10^9)
OutPut
Number of outputs 0

Ideas:

A 0 can only be obtained by 2*5. Statistics n! the number of 2 and the number of 5, take less. That is, the number of 5 in n! is obtained. "Number theory: [n/5]+[n/5^2]+[n/5^3]+[n/5^4]+ ...]" {I can also draw this conclusion from my own analysis}

Code:

int Main () {    int  n;     >> N;    ll ans=0;    ll tmp=5;      while (tmp<=N) {        ans+ = (n/tmp);        TMP*=5;    }    Print ("%lld\n", ans);         0 ;}

51nod_1003 factorial 0 of the number (5 in the n!, number theory)

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.