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)
- 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
- 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
- Smallest odd digits number not less than N
- Smallest even digits number not less than N
- Smallest number with sum of digits as N and divisible by 10^N
- Find the smallest number whose digits multiply to a given number n
- Smallest number k such that the product of digits of k is equal to n
- Smallest number by rearranging digits of a given number
- Immediate smallest number after re-arranging the digits of a given number
- Find the smallest positive number which can not be represented by given digits
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.