2015! is multiplied by itself 2015 times as follows:
2 0 1 5 2 0 1 5 ! × 2 0 1 5 ! × ⋯ × 2 0 1 5 ! .
Count how many trailing zeros there are!
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.
Nice Solution
Check problem statement again.
I didnt get why you multiplied by 2015 in the end
Log in to reply
He got the number of trailing zero's in 2015! only, but we have 2015! 2015 times, hence we multiply by 2015.
If we write n = 2 0 1 5 to base 5, we end up with 31030; the sum of the digits is s = 7 . According to Legendre's Theorem, the factor p = 5 appears p − 1 n − s = 5 0 2 times in 2 0 1 5 ! . Thus 5 appears 5 0 2 × 2 0 1 5 = 1 0 1 1 5 3 0 times in ( 2 0 1 5 ! ) 2 0 1 5 . Since 2 appears more frequently, namely 2 0 1 5 − 1 0 = 2 0 1 0 times in 2015, the number ( 2 0 1 5 ! ) 2 0 1 5 will have 1 0 1 1 5 3 0 trailing zeros.
C++ implementation of the formula : [https://ideone.com/rcGY1E) We go with 1 test case and enter 2015 as we are querying for 2015! Now the algorithm will give 502 as output which is the number of trailing zeroes in 2015! . There are total 2015 occurrences of (2015!) because the original query is 2015 * (2015!). Each 2015! gives 502 trailing zeros,hence 2015 such occurrence will give a total of 2015 * 502 trailing zeroes!
Problem Loading...
Note Loading...
Set Loading...
In any prime factorization, only a product of 2 and 5 generates a trailing zero, so we need to count the "2*5" pairs in the prime factorization of this number.
To make things easier, only the "5" factors need counting as "5" appears less frequently than the "2" factors. Take 2015! for starters:
2015/5 = 403. This is how many numbers in the product 2015! contain the prime factor 5 at least once.
floor(2015/(5^2)) = 80. This is how many numbers in the product 2015! contain the prime factor 5 at least twice.
floor(2015/(5^3)) = 16. This is how many numbers in the product 2015! contain the prime factor 5 at least thrice.
floor(2015/(5^4)) = 3. This is how many numbers in the product 2015! contain the prime factor 5 exactly four times . We need no more.
403+80+16+3=502 is the number of times "5" appears in the prime factorization of 2015! (no exclamation intended)
So the answer is 2015*502 = 1011530 trailing zeros.