We are given an integer N. We need to write a program to find the least positive integer X made up of only digits 9’s and 0’s, such that, X is a multiple of N.
Note: It is assumed that the value of X will not exceed 106.
Input : N = 5 Output : X = 90 Exaplanation: 90 is the smallest number made up of 9's and 0's which is divisible by 5. Input : N = 7 Output : X = 9009 Exaplanation: 9009 is smallest number made up of 9's and 0's which is divisible by 7.
The idea to solve this problem is to generate and store all of the numbers which can be formed using digits 0 & 9. Then find the smallest number among these generated number which is divisible by N.
We will use the method of generating binary numbers to generate all numbers which can be formed by using digits 0 & 9.
Below is the implementation of above idea:
Time Complexity: O(n)
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Smallest multiple of N formed using the given set of digits
- Nth number made up of odd digits only
- Find the n-th number made of even digits only
- Find smallest number with given number of digits and sum of digits under given constraints
- Smallest number with given sum of digits and sum of square of digits
- Number of digits in the nth number made of given four digits
- Find smallest number with given number of digits and sum of digits
- Find the smallest binary digit multiple of given number
- Reduce the number to minimum multiple of 4 after removing the digits
- Smallest even digits number not less than N
- Smallest odd digits number not less than N
- Find smallest possible Number from a given large Number with same count of digits
- Smallest number with sum of digits as N and divisible by 10^N
- Smallest number whose sum of digits is square of N
- Smallest number whose square has N digits
- Find the smallest number whose sum of digits is N
- Find the smallest number whose digits multiply to a given number n
- Smallest number containing all possible N length permutations using digits 0 to D
- Smallest number greater than or equal to N using only digits 1 to K
- Smallest N digit number with none of its digits as its divisor
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.