java - Counting trailing zeros of numbers resulted from factorial -


I am trying to calculate zero numbers of numbers that are from the results (which means that the number is big enough is). Takes the following code number, calculate the number of factorial, and count the indexed zero. However, when the number is about as big as 25 !, numzeros do not work.

  public static zero main (string [] args) {BufferedReader br = new BufferedReader (new InputStreamReader .in)); Double facts; Integer answer; Try {int number = integer Paradent (breadline) (); Fact = factorial (number); Answer = numZeros (fact); } Hold (NumberFormatException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); }} Public stable double factorial (int no) {double total = 1; For (int i = 1; i  

I am not concerned about the efficiency of this code, and I know there are several ways to improve this code. I am trying to understand why counting more than 25 numbers is being counted! not working.

Any thoughts?

Do not count your work factual but the number of zeros is a good solution (which you have to prove Can try) using the formula

  def zero (n): i = 1 result = 0 while n & gt; = I: i * = 5 results + = N / i # (take a floor like Python or Java) Return result  

Hope you can translate it into Java [N / 5] + [n / 25] + [n / 125] + [n / 625] + ... and divides when the separator grows larger than N calculates.

No Use BigIntegers This is a boozers, such solutions require seconds of time for large numbers.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -