

- 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 count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python
Suppose we have a number k, now consider the smallest positive integer value x where all values from 1 to k divide evenly. In other words, consider the smallest value x where x is divisible by all numbers from 1 through k. We have to find the number of trailing zeroes in x.
So, if the input is like k = 6, then the output will be 0, as the smallest x here is 60, 60 can be divided using 1, 2, 3, 4, 5 and 6. There is only one trailing zeroes in 60.
To solve this, we will follow these steps −
res := 0
x := 1
while x * 5 <= k, do
res := res + 1
x := x * 5
return res
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, k): res = 0 x = 1 while x * 5 <= k: res += 1 x *= 5 return res ob = Solution() k = 6 print(ob.solve(k))
Input
6
Output
1
- Related Questions & Answers
- Python Program for Smallest K digit number divisible by X
- C++ Program for Largest K digit number divisible by X?
- C++ Program for Smallest K digit number divisible by X?
- Java Program for Largest K digit number divisible by X
- Java Program for Smallest K digit number divisible by X
- Count number of trailing zeros in product of array in C++
- Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*.. in C++
- Count trailing zeros in factorial of a number in C++
- Count the number of elements in an array which are divisible by k in C++
- Largest K digit number divisible by X in C++
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Python program to find tuples which have all elements divisible by K from a list of tuples
- Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python
- C++ Program for the Largest K digit number divisible by X?
- C Program to count trailing and leading zeros in a binary number
Advertisements