Trailing Zeros in the Product of First 2017 factorials

Find the trailing number of zeros of

1 ! × 2 ! × × 2017 ! . 1! \times 2! \times \cdots \times 2017!.


This problem belongs to the series Trailing Zeros in the Product of the First n n Factorials .


The answer is 504256.

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

The following C code solves the problem:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>

int leading(int n){
    int i, ans = 0;
    for(i = 5; i <= n; i+=5){
        int pot = 0, j = i;
        while(j % 5 == 0){
            pot++;
            j /= 5;
        }
        ans += pot * (n - i + 1);
    }
    return ans;
}

int main(){
    int n;
    scanf("%d", &n);
    printf("%d", leading(n));
    return 0;
}

Let x = i = 1 n i ! x=\displaystyle \prod_{i=1}^{n} i! , note that we can rewrite it as x = i = 1 n i n i + 1 x=\displaystyle \prod_{i=1}^{n} i^{n-i+1} . We need to find the highest k k such that 1 0 k x 10^k \mid x . But 10 = 2 × 5 10=2\times 5 , and since 2 2 will appear more times than 5 5 in the prime factorization of x x , we only need to find the highest k k such that 5 k x 5^k \mid x .

So, we iterate from i = 1 i=1 to i = n i=n , count the number of times that 5 5 can divide i i and multiply that by n i + 1 n-i+1 . Finally, we sum all of these results and that will be the answer.

Alternatively we realise That each factorial greater than 4! Would have a collection of 2's and 5's as it's factors As no.of 2's present would exceed the no.of 5's by large, By De-Poignac's Formula We only find the highest powers of 5 present in
Say N! (A particular N) And then add up the result from N=1 to 2017 To get what is desired

Suhas Sheikh - 3 years ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...