Java factorial calculation to obtain the result of the end of the number of 0 code implementation _java

Source: Internet
Author: User

After seeing the topic, analysis, the factorial of 10 is already very big. The calculation of the end of the number of 0, completely unrealistic, even if the implementation is also very troublesome.

Later, when you think of a number in the factorial of the product has 5 end of the number should be at the end of the result of a 0.

Put it into practice, test a few, no mistakes.

Posted out, we look, have a problem in time to advise:

Copy Code code as follows:

/**
* To find the number of n among the 1000~10000 and calculate the number of n! at the end of how many 0?
*/
public static void Test2 (int number) {
int count = NUMBER/5;
System.out.println (count);
}

After reviewing the knowledge of mathematics, the above calculation should be wrong.

It should be written as follows, +1 times per 5 multiples.

Copy Code code as follows:

int x = 10000;
while (x>0)
{
Count = count + x/5;
x = X/5;
}
System.out.println (count);

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.