- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find number m such that it has n number of 0s at end in Python

Suppose we have a number n. We have to find smallest number m, such that factorial of m has at least n number of 0s.

So, if the input is like n = 2, then the output will be 10 because 10! = 3628800 and 9! = 362880, minimum number with 2 zeros is 10.

To solve this, we will follow these steps −

- Define a function count_fives() . This will take n
- cnt := 0
- while n > 0, do
- n := floor of (n / 5)
- cnt := cnt + n

- return cnt
- From the main method, do the following −
- left := 1
- right := 5^24
- while right - left > 5, do
- mid := floor of ((right + left) / 10) * 5
- fives := count_fives(mid)
- if fives is same as n, then
- right := mid
- left := right - 5
- come out from the loop

- otherwise when fives < n, then
- left := mid

- otherwise,
- right := mid

- return right

## Example

Let us see the following implementation to get better understanding −

def count_fives(n): cnt = 0 while n > 0: n = n // 5 cnt += n return cnt def solve(n): left = 1 right = 5**24 while right - left > 5: mid = int((right + left) / 10) * 5 fives = count_fives(mid) if fives == n: right = mid left = right - 5 break elif fives < n: left = mid else: right = mid return right n = 2 print(solve(n))

## Input

2

## Output

10

- Related Questions & Answers
- Find a positive number M such that gcd(N^M,N&M) is maximum in Python
- Print n 0s and m 1s such that no two 0s and no three 1s are together in C Program
- Program to find remainder after dividing n number of 1s by m in Python
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M in Python
- Find the number of consecutive zero at the end after multiplying n numbers in Python
- Find smallest number n such that n XOR n+1 equals to given k in C++
- Print an N x M matrix such that each row and column has all the vowels in it in C++
- Convert a number of length N such that it contains any one digit at least 'K' times in C++
- Check if a string has m consecutive 1s or 0s in Python
- C++ Program to Generate N Number of Passwords of Length M Each
- Check if the binary representation of a number has equal number of 0s and 1s in blocks in Python
- Program to find minimum number of days to make m bouquets using Python
- Find M-th number whose repeated sum of digits of a number is N in C++
- Find the minimum number of steps to reach M from N in C++
- Program to find number of pairs (i, j) such that ith and jth elements are same in Python

Advertisements