> For the complete documentation index, see [llms.txt](https://soumyajit4419.gitbook.io/ds-algo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://soumyajit4419.gitbook.io/ds-algo/maths/5.factorial-trailing-zeroes.md).

# 4.Factorial Trailing Zeroes

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

## Solution:

**Divide a number by 5 and add all the quotients.**

```cpp
class Solution
{
public:
    int trailingZeroes(int n)
    {

        int count = 0;
        while (n > 0)
        {
            int p = n / 5;
            count = count + p;
            n = p;
        }
        return count;
    }
};
```

**Time Complexity: O(log n)**
