Don't be intimidated by factorial.

Source: Internet
Author: User

Q: Given an integer n, how many 0 are there at the end of the factorial n! of n? For example: N = 10,n! = 3628800, n! at the end of the two X 0

Analysis and Solution:

Some people encounter such problems, is not to complete the calculation of the value of n!? What if it overflows? In fact, the problem becomes simple if we take the view that "which numbers multiply to get 10".

Consider first, if n! = k * 10M, and K cannot be divisible by 10, then n! at the end of M 0. Then consider the decomposition of the n! to the mass factor, N! = (2X) * (3Y) * (5Z) ....., because 10=2*5, so M is only related to X and Z, each pair of 2 and 5 can get a 10, so M=min (X,z). It is not difficult to see that X is greater than or equal to Z, because the number that can be divisible by 2 is much higher than the number that can be divisible by 5, so the formulation is simply m=z.

Don't be intimidated by factorial.

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.