- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program for Smallest K digit number divisible by X
In this article, we will learn about the solution and approach to solve the given problem statement.
Integers n and d are given. We need to find the smallest n-digit number divisible by d.
1. FirstNow let's we compute MIN : smallest n-digit number (1000...n-times)
2. Now, If MIN % X is 0, ans = MIN
3. else, ans = (MIN + X) - ((MIN + X) % X))
This is because there will be a number in range [MIN...MIN+X] which is divisible by d.
Now let’s see the implementation −
def answer(n, d): # Computing MAX Min = pow(10, d-1) if(Min%n == 0): return (Min) else: return ((Min + n) - ((Min + n) % n)) n = 83 d = 5 print(answer(n, d))
All the variables are declared in the global frame as shown in the figure given below −
In this article, we learnt about the approach to find Smallest K digit number divisible by X
- C++ Program for Smallest K digit number divisible by X?
- Java Program for Smallest K digit number divisible by X
- C++ Programming for Smallest K digit number divisible by X?
- C++ Program for Largest K digit number divisible by X?
- Java Program for Largest K digit number divisible by X
- C++ Program for the Largest K digit number divisible by X?
- Largest K digit number divisible by X in C++
- Smallest Integer Divisible by K in Python
- Find nth number that contains the digit k or divisible by k in C++
- Count n digit numbers divisible by given number in C++
- Program to count number of trailing zeros of minimum number x which is divisible by all values from 1 to k in Python
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Program to find smallest value of K for K-Similar Strings in Python
- Program to find length of smallest sublist that can be deleted to make sum divisible by k in Python