Smallest multiple of N with exactly N digits in its Binary number representation Last Updated : 27 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Given a positive integer N, the task is to find the smallest multiple of N with exactly N digits in its binary number representation.Example: Input: N = 3 Output: 6 Explanation: 6 is the smallest multiple of 3 and has length also 3(110) in binary.Input: N = 5 Output: 20 Explanation: 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: N*\lceil 2^\frac{N-1}{N} \rceil Therefore, the number N is taken as the input and the above formula is implemented. Below is the implementation of the above approach: C++ // C++ program to find smallest // multiple of n with exactly N // digits in Binary number System. #include <iostream> #include <math.h> using namespace std; // Function to find smallest multiple // of n with exactly n digits // in Binary number representation. void smallestNumber(int N) { cout << N * ceil(pow(2, (N - 1)) / N); } // Driver code int main() { int N = 3; smallestNumber(N); return 0; } Java // Java program to find smallest // multiple of n with exactly N // digits in Binary Number System. class GFG{ // Function to find smallest // multiple of n with exactly N // digits in Binary Number System. static void smallestNumber(int N) { System.out.print(N * Math.ceil (Math.pow(2, (N - 1)) / N)); } // Driver code public static void main(String[] args) { int N = 3; smallestNumber(N); } } // This code is contributed by shubham Python3 # Python3 program to find smallest # multiple of n with exactly N # digits in Binary number System. from math import ceil # Function to find smallest multiple # of n with exactly n digits # in Binary number representation. def smallestNumber(N): print(N * ceil(pow(2, (N - 1)) / N)) # Driver code N = 3 smallestNumber(N) # This code is contributed by Mohit Kumar C# // C# program to find smallest // multiple of n with exactly N // digits in Binary Number System. using System; class GFG{ // Function to find smallest // multiple of n with exactly N // digits in Binary Number System. static void smallestNumber(int N) { Console.Write(N * Math.Ceiling( Math.Pow(2, (N - 1)) / N)); } // Driver code public static void Main(string[] args) { int N = 3; smallestNumber(N); } } // This code is contributed by AnkitRai01 JavaScript <script> // Javascript program to find smallest // multiple of n with exactly N // digits in Binary number System. // Function to find smallest multiple // of n with exactly n digits // in Binary number representation. function smallestNumber(N) { document.write(N * parseInt(Math.ceil(Math.pow(2, (N - 1)) / N))); } // Driver code let N = 3; smallestNumber(N); // This code is contributed by rishavmahato348. </script> Output: 6 Time Complexity: O(n)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Smallest multiple of N with exactly N digits in its Binary number representation S spp____ Follow Improve Article Tags : Mathematical DSA Practice Tags : Mathematical Similar Reads Find the smallest binary digit multiple of given number A decimal number is called a binary digit number if its digits are binary. For example, 102 is not a binary digit number and 101 is.We are given a decimal number N, we need to find the smallest multiple of N which is a binary digit number, Examples: Input : N = 2 Output: 10 Explanation: 10 is a mult 7 min read Next greater number than N with exactly one bit different in binary representation of N Given a number N. The task is to find the smallest number which is greater than N and has only one bit different in the binary representation of N. Note: Here N can be very large 10^9 < N < 10^15.Examples: Input : N = 11 Output : The next number is 15 The binary representation of 11 is 1011 So 7 min read 1 to n bit numbers with no consecutive 1s in binary representation. Given a number n, our task is to find all 1 to n bit numbers with no consecutive 1s in their binary representation. Examples: Input : n = 4 Output : 1 2 4 5 8 9 10 These are numbers with 1 to 4 bits and no consecutive ones in binary representation. Input : n = 3 Output : 1 2 4 5 Recommended: Please 6 min read Sum of decimals that are binary representations of first N natural numbers Given a positive integer N, the task is to calculate the sum of all decimals which can be expressed as binary representations of first N natural numbers. Examples: Input: N = 3Output: 22Explanation:The Binary Representation of 1 is 01.The Binary Representation of 2 is 10.The Binary Representation of 9 min read Binary representation of next greater number with same number of 1's and 0's Given a binary input that represents binary representation of positive number n, find binary representation of smallest number greater than n with same number of 1's and 0's as in binary representation of n. If no such number can be formed, print "no greater number".The binary input may be and may n 12 min read Like