![]() |
VOOZH | about |
Given two integers X and K, the task is to find the smallest K-digit number that is perfectly divisible by X. For example:
Input: X = 5, K = 2
Output: 10
Explanation: 10 is the smallest 2-digit number divisible by 5.
Let's explore different methods to solve this problem efficiently in Python.
This method uses the math.ceil() function to compute the smallest multiple of X greater than or equal to 10 ^ (K-1) in a single step. It’s concise and efficient.
10043
Explanation:
In this method, we directly calculate the smallest K-digit number (10 ^ (K-1)) and then find the next multiple of X that is greater than or equal to it.
10043
Explanation:
This approach iteratively checks numbers starting from the smallest K-digit number until it finds one divisible by X. It’s simple but less efficient for large inputs.
10043
Explanation:
Although not practical for large inputs, this method shows how list comprehension can find the first K-digit number divisible by X quickly for small ranges.
10043
Explanation:
Please refer complete article on Smallest K digit number divisible by X for more details!