Trailing Zero

We know,

N! = 1 X 2 X 3 X ........ X (N-1) X N .

Now , 5! = 1 X 2 X 3 X 4 X 5 = 120 .

So 5! contains one trailing 0 .

Now you to tell me , how many trailing zero contains 1000000!


The answer is 249998.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Parveen Soni
Oct 29, 2014

keep on dividing 1000000 to 5^1 and 5^2 and 5^3 and so on till you get value less than one.
now add values of all division and you will get answer

For Programmer my java program is --------------------------------------->>>>>> public class program {
public static void main(String[] args)
{ System.out.println(countTrailingZerosOfFactorial(1000000)); }
private static final int countTrailingZerosOfFactorial(final int n) {
int count = 0;
for (int factor = 5; factor <= n; factor += 5) count += countFives(factor); return count; }
private static final int countFives(int factor) {
if (!divides(5, factor))
return 0;
return 1 + countFives(factor / 5); }
private static final boolean divides(final int d, final int n) { return n % d == 0; }
}

Parveen Soni - 6 years, 7 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...