# C#LeetCode刷题之#172-阶乘后的零（Factorial Trailing Zeroes）

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

Input: 3

Output: 0

Explanation: 3! = 6, no trailing zero.

Input: 5

Output: 1

Explanation: 5! = 120, one trailing zero.

Note: Your solution should be in logarithmic time complexity.

```public class Program {

public static void Main(string[] args) {
var n = 18;

var res = TrailingZeroes(n);
Console.WriteLine(res);

}

private static int TrailingZeroes(int n) {
//统计包含因子5的数量即可
var res = 0;
while(n > 1) {
res += (n /= 5);
}
return res;
}

}```

`3`