Given a positive integer N, the task is to find the smallest multiple of N with exactly N digits in its binary number representation.
Input: N = 3
6 is the smallest multiple of 3 and has length also 3(110) in binary.
Input: N = 5
6 is the smallest multiple of 5 and has length also 5(10100) in binary.
Approach: The idea is to make an observation.
- If we observe carefully a series will be formed as 1, 2, 6, 8, 20, …
- The N-th term in the series would be:
- Therefore, the number N is taken as the input and the above formula is implemented.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count digits in a factorial | Set 2
- Write a program to reverse digits of a number
- Write an Efficient Method to Check if a Number is Multiple of 3
- Write an Efficient C Program to Reverse Bits of a Number
- Minimum number of jumps to reach end
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Print all combinations of points that can compose a given number
- Count of Binary Digit numbers smaller than N
- Check if a number is multiple of 5 without using / and % operators
- Given a number, find the next smallest palindrome
- Count the number of possible triangles
- Select a random number from stream, with O(1) space
- Find the largest multiple of 2, 3 and 5
- Program to convert a given number to words
- Efficient program to print all prime factors of a given number
- Count numbers with same first and last digits
- Check if a number is Palindrome
- Random number generator in arbitrary probability distribution fashion
- Count digits in given number N which divide N
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.