Leetcode-172: Factorial Trailing Zeroes

In this question, it should be noted that not only n/5, but also the case where n/5 is a multiple of 5, you must continue to n/5. For example, 25/5=5, then this 5 should also be taken into account.
code show as below:

#include <iostream>

using namespace std;

int trailingZeroes(int n) {
    int count=0;
    while(n) {
        n/=5;
        count+=n;
    }
    return count;
}

int main()
{
    cout<<trailingZeroes(25)<<endl;

    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325640925&siteId=291194637