Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
思路:算出前n个数分解质因数后的5的幂的次数和
class Solution {
public:
int trailingZeroes(int n) {
int numberOf5=0;int quo=0;
while(n>4){
quo=n/5;
numberOf5=numberOf5+quo;
n=n/5;
}
return numberOf5;
}
};
Other solutions: