Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
class Solution {
public:
//refer to http://en.wikipedia.org/wiki/Trailing_zero
//q0 = n, q(k+1) = q(k)/5 until q(k+1) = 0
int trailingZeroes(int n) {
int q0,q1;
int sum = 0;
q0 = n;
do{
q1 = q0/5;
q0 = q1;
sum += q0;
}while(q0/5);
return sum;
}
};