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

# 4.Factorial Trailing Zeroes

## 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)**
