Given a number N and base b if N in base b representation starts with 1 print Yes else print No
Input : n = 6, b = 4 Output : Yes 6 can be written as in base 4 so answer is Yes as it starts with 1 Input : n = 24, b = 2 Output : Yes 24 can be written as in base 2 so answer is Yes as it starts with 1 Input : n = 24, b = 7 Output : No 24 can be written as in base 7 so answer is No as it starts with 3
When a number N is represented in base ‘b’ it gets converted to m+1 length sequence ….. which implies * + *…..+* = N
The smallest number in base b and starting with ‘1’ i.e. 100..00 and m+1 digits in base is
and largest number is 2*-1.So N should lie in this range.
<= N <= 2*-1
Now another thing to notice is that m cannot exceed floor((N)) because when we represent any number in base-2 it gets converted into a sequence of only 1s and 0s so the length of this sequence will always be greater than any other base representation and its length will be equal to floor((N))+1.
So to check for a given base 'b' if N starts with 1 or not we will traverse from m = 1 to m = floor((N)) and check if for any m N lies in the range <= N <= 2*-1 or not and accordingly print "Yes" or "No".
Yes Yes No Yes
This article is contributed by Ayush Jha. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check if a number is divisible by all prime divisors of another number
- Check if a number with even number of digits is palindrome or not
- Program to check whether a number is Proth number or not
- Check if a number is a Trojan Number
- Check if a number is an Achilles number or not
- Check if a number is an Unusual Number or not
- Check whether a number is Non-hypotenuse number
- Check if a number is a Mystery Number
- Check Whether a number is Duck Number or not
- Check whether the given number is Euclid Number or not
- Check if a number is a Krishnamurthy Number or not
- Check if a number is Triperfect Number
- How to check if a given number is Fibonacci number?
- Check if a number is a power of another number