Given the integers a, b, N, the task is to find the largest number x such that is an N-digit number of base b.
Input: a = 2, b = 10, N = 2
Here 2 * 33 = 54, which has number of digit = 2,
but 2 * 44 = 512 which has number of digits = 3, which is not equal to N.
Therefore the largest value of x is 2.
Input: a = 1, b = 2, N = 3
1 * 22 = 4 whose binary representation is 100 and it has 3 digits.
Approach: This problem can be solved using binary search.
- Number of digits of in base is .
- Binary search is used to find the largest such that the number of digits of in base is exactly .
- In binary search, we will check the number of digits , where , and change the pointer according to that.
Below is the implementation of the above approach:
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.
- Largest N digit number in Base B
- Find the Largest N digit perfect square number in Base B
- Given a number N in decimal base, find number of its digits in any base (base b)
- Find the Nth digit from right in base B of the given number in Decimal base
- Given a number N in decimal base, find the sum of digits in any base B
- Largest Even and Odd N-digit numbers of base B
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- Add two integers of different base and represent sum in smaller base of the two
- Check if a number is in given base or not
- Pandigital number in a given base
- Complement of a number with any base b
- Check if a N base number is Even or Odd
- Check whether a number has consecutive 0's in the given base or not
- Check if a number N starts with 1 in b-base
- Number System and Base Conversions
- Find most significant bit of a number X in base Y
- Convert a number into negative base representation
- Find the length of factorial of a number in any given base
- Check if the number is even or odd whose digits and base (radix) is given
- Number of trailing zeroes in base B representation of 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 email@example.com. 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.