Leetcode Algorithms -- Factorial Trailing Zeroes
Factorial Trailing Zeroes (Easy)
Description
Given an integer n, return the number of trailing zeroes in n!.
Note: Your solution should be in logarithmic time complexity.
Analysis
简单数论题,我们可以知道n!的最后的尾0的个数取决于n!中2和5的因子的个数。
而5的个数肯定比2要小,因此我们只要求出n!中有多少个5。
ans = [N/5] + [N/5^2] + [N/5^3]+….
My Solution
1 | //C++ |