So let's figure out how many zeros we have at the end of 1000 factorial

  • 2020-04-01 02:59:15
  • OfStack

A prime number is an important concept in scientific computation. A prime number is also called a prime number. The primes are the purest Numbers, the ones without any other elements, and all the other Numbers can be said to be multiplied by primes. So it's important to understand prime Numbers well for mathematics and programs.

The question is: find 1000! How many zeros are at the end of the result


1000! = 1 x 2 x 3 x 4 x 5 x ... x 999 x 1000


public static void main(String[] args) {
 
 
 

 //The sum of The Times divided by 2
 int count2 = 0;
 //The sum of The Times divided by 5
 int count5 = 0;

 //Let's go through all the Numbers
 for (int number = 1; number <= 1000; number ++) {
  int dynmicNumber = number;//A copy of the number used for an uncounted divisible division
  while (dynmicNumber % 2 == 0) { //Count how many times the number is divisible by 2, but not separately, but globally
   count2++;
   dynmicNumber /= 2;
  }
  while (dynmicNumber % 5 == 0) { //Count how many times the number is divisible by 2, but not separately, but globally
   count5++;
   dynmicNumber /= 5;
  }
 }

 System.out.println(" At the end 0 Is: " + Math.min(count2, count5));
 
}


Related articles: