How many 0_java are there at the end of the result of 1000 factorial?

Source: Internet
Author: User

Prime is a very important concept in scientific calculation, Prime is also called prime number. Prime is the purest number, there is no other element, and the other numbers are multiplied by primes. Therefore, the understanding of good primes, for mathematics and procedures, has important significance.

The title is: Ask 1000! Number 0 at the end of the result

Copy Code code as follows:

1000! = 1x2x3x4x5x...x999x1000

Copy Code code as follows:

public static void Main (string[] args) {
The factorial of/*1000 is astronomical, so it is impossible to calculate and see how many 0*/
* Problem-solving ideas: Two primes 2, 5, multiplied to get 10, we can think, how many groups 2, 5, the end of how many 0 * *
/* Operation Method: Operation 1 to 1000 of all the number, to see each number can be 2 and 5 divisible by several times, and statistics, respectively, the assumption is 2 evenly divided 8 times by 5 Division 12 times, then we can think of 8 groups (2,5), that is 8 0*/

The sum of the number of times divisible by 2
int count2 = 0;
The sum of the number of times divisible by 5
int count5 = 0;

Iterate through all the numbers
for (int number = 1; number <= 1000 number + +) {
int dynmicnumber = number;//A copy of the number used for the division of Numbers
while (dynmicnumber% 2 = 0) {//statistics how many times this number can be divisible by 2, but not separately, but statistically to the global
count2++;
Dynmicnumber/= 2;
}
while (dynmicnumber% 5 = 0) {//statistics how many times this number can be divisible by 2, but not separately, but statistically to the global
count5++;
Dynmicnumber/= 5;
}
}

System.out.println ("The number of end 0 is:" + math.min (Count2, count5));
/* Prime is a very important concept in scientific calculation, can be understood as a very simple meaning, such as: white Paper, Bai Suzhen, elements. Prime is also called prime number, quality can also be understood as pure meaning bar, mass, substance, essence.
* Element and quality is the quality, the quality used to describe people's words, can be understood as: the most basic moral, the most primitive human nature, and so on.
* Prime is the purest number, there is no other component of the number, the other number can be said to be multiplied by prime numbers.
* Therefore, the understanding of good primes, for mathematics and procedures, has important significance. */
}

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.