/**172. Factorial Trailing Zeroes *2016-6-4 by Mingyang * First do not forget what is factorial, is factorial. Then it is easy to think of the number of statistics * (2,5) pairs, because 2x5=10. But the condition is relaxed and you will find that just a few 5 of the number is good, * because 2 is actually more than 5. Then the title translates into the sum of approximately 5 of the numbers from 1 to N. * Very simple to think can be used N/5 get. For example, when n is 19, 19/5 = 3.8, then there are 3 approximations containing 5, 5, 10, * 15, respectively. But some of the numbers may be divisible by 5, say 25. Such a number can contribute several 5 to the final factorial. * The Final solution is to sum the n/5+n/25+n/125+...+ and stop when n is less than the denominator. The denominator is 5^1, 5^2, 5^2 ... * in this case, in the calculation of 5^2, can be divisible by 25 of the number of two 5, one of which has been calculated in the 5^1. So the 5^2 is added directly to count. */ Public Static intTrailingzeroes (intN) {if(n<0)return-1; intCount = 0; for(Longi=5; n/i>=1; I*=5) {Count+ = N/i; } returncount; }
172. Factorial Trailing Zeroes