Let n be any power raised to base 2 i.e 2n. We are given the number n and our task is to find out the number of digits contained in the number 2n.
Input : n = 5 Output : 2 Explanation : 2n = 32, which has only 2 digits. Input : n = 10 Output : 4 Explanation : 2n = 1024, which has only 4 digits.
We can write 2n using logarithms as:
2n = 10nlog102
Now suppose, x = nlog102,
Therefore, 2n = 10x
Also, we all know that the number, 10n will have (n+1) digits. Therefore, 10x will have (x+1) digits.
Or, we can say that 2n will have (x+1) digits as 2n = 10x.
Therefore, number of digits in 2n = (nlog102) + 1
Below is the implementation of above idea:
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.
- Find last five digits of a given five digit number raised to power five
- Print last k digits of a^b (a raised to power b)
- Check if a number can be expressed as x^y (x raised to power y)
- Minimum removals in a number to be divisible by 10 power raised to K
- Larger of a^b or b^a (a raised to power b or b raised to power a)
- Find the sum of power of bit count raised to the power B
- GCD of a number raised to some power and another number
- Find value of y mod (2 raised to power x)
- K-th digit in 'a' raised to power 'b'
- Sum of absolute difference of all pairs raised to power K
- Find unit digit of x raised to power y
- Find multiple of x closest to or a ^ b (a raised to power b)
- Sum of digits of a given number to a given power
- Number of digits in N factorial to the power N
- Find the first and last M digits from K-th power of N
- Check if given number is a power of d where d is a power of 2
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
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.