LeetCode 172 Factorial Trailing Zeroes (zero after Factorial )(*)
Translation
Given an integer n, return n! The number of zeros. Note: Your solution should be within the log time complexity.
Original
Given an integer n, return the number of trailing zeroes in n !. Note: Your solution shocould be in logarithmic time complexity.
Analysis
At first, I did not pay too much attention when reading the question. I thought it was just a fraction of the number n. Although I thought it would not be that simple ...... I wrote a piece of code and submitted it. The result WA prompts me that 1 should be returned if 5 is returned. This is why I am wondering, the number of hairs after 5 is 0 ...... Read the questions ...... Oh, it turns out to be a factorial. I have met this question.
If there is zero at the end, there must be five in the factorial process. If it is 10, there will be two numbers that can be divisible by five, 10 and 5, and so on ......
Just now I went to look for the blog I wrote. You can check it out. It's very interesting. Using Functional Language LISP, we can find the 20000 factorial. ^_^
Is it true that 100 of the class cannot be counted?
Code
Class Solution {public: int trailingZeroes (int n) {int count = 0; while (n> 1) count + = (n/= 5); return count ;}};