# LeetCode:Factorial Trailing Zeroes

### Factorial Trailing Zeroes

Total Accepted: 61757 Total Submissions: 185808 Difficulty: Easy

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Credits:
Special thanks to @ts for adding this problem and creating all test cases.

Subscribe to see which companies asked this question

1.题意求n!中后缀0的个数。

2.n!=1*2*3*...*n，中的0由(2^i) * (5^j)得来。

3.即要计算min(i,j)。

4.j<=i，直观的来看：i是逢2进1，j是逢5进1。固只需计算5的个数。

c++ code：

class Solution {
public:
int trailingZeroes(int n) {
int x = 5;
int ret = 0;
while(x <= n) {
ret += n/x;
x *= 5;
}
return ret;
}
};

class Solution {
public:
int trailingZeroes(int n) {
int ret = 0;
while(n) {
ret += n/5;
n /= 5;
}
return ret;
}
};

## Leetcode Problem.172—Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in lo...

## LeetCode题解——Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in ...

## LeetCode: Factorial Trailing Zeroes

1 题目2 寻找阶乘的特点定义： 一个正整数的阶乘（英语：factorial）是所有小于及等于该数的正整数的积，并且有0的阶乘为1。亦即n!=1×2×3×…×n。阶乘亦可以递归方式定义：0!=1，n...

## leetcode 172. Factorial Trailing Zeroes

DescriptionGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should...

## leetcode172：Factorial Trailing Zeroes

• hjxzb
• 2015年04月07日 10:37
• 461

## <LeetCode OJ> 172. Factorial Trailing Zeroes

172. Factorial Trailing Zeroes My Submissions Question Total Accepted: 45801 Total Submissions: ...

## [leetcode]Factorial Trailing Zeroes

举报原因： 您举报文章：LeetCode:Factorial Trailing Zeroes 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)