Given a number and no. of digits to represent the number, find if given number can be represented in given no. of digits in any base from 2 to 32.
Input: 8 4 Output: Yes Possible in base 2 as 8 in base 2 is 1000 Input: 8 2 Output: Yes Possible in base 3 as 8 in base 3 is 22 Input: 8 3 Output: No Not possible in any base
We strongly recommend you to minimize your browser and try this yourself first.
The idea is to check all bases one by one starting from base 2 to base 32. How do we check for a given base? Following are simple steps.
1) IF number is smaller than base and digit is 1, then return true.
2) Else if digit is more than 1 and number is more than base, then remove the last digit from num by doing num/base, reduce the number of digits and recur.
3) Else return false
Below is the implementation of above idea.
This article is contributed by Mehboob Elahi. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Given a number N in decimal base, find number of its digits in any base (base b)
- 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
- Check if a number is power of k using base changing method
- Check whether a number can be represented by sum of two squares
- Check if a number can be represented as sum of non zero powers of 2
- Check if a number can be represented as a sum of 2 triangular numbers
- Check if given number can be represented as sum of two great numbers
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- All possible numbers of N digits and base B without leading zeros
- Check if a number has digits in the given Order
- Check if all digits of a number divide it
- Check if the Xor of the frequency of all digits of a number N is zero or not
- Check if the sum of digits of a number N divides it
- Check if the frequency of all the digits in a number is same