- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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
Advertisements