Given positive integers N and K, the task is to find the highest and smallest power of K greater than equal to and less than equal to N respectively.
Input: N = 3, K = 2
Output: 2 4
Highest power of 2 less than 3 = 2
Smallest power of 2 greater than 3 = 4
Input: N = 6, K = 3
Output: 3 9
Highest power of 3 less than 6 = 2
Smallest power of 3 greater than 6 = 9
- Compute the log of N in base K (logK N) to get the exponential power such that K raised to this exponent is the Highest power of K less than equal to N.
- For the Smallest power of K less than equal to N, find the next power of K computed from the last step
Below is the implementation of the above approach:
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Smallest power of 2 greater than or equal to n
- Smallest power of 4 greater than or equal to N
- Highest power of 2 less than or equal to given number
- Highest power of 2 less than or equal to given Integer
- Smallest number greater than n that can be represented as a sum of distinct power of k
- Smallest number greater than or equal to N divisible by K
- Smallest number greater than or equal to X whose sum of digits is divisible by Y
- Smallest Special Prime which is greater than or equal to a given number
- Highest power of 2 that divides a number represented in binary
- Count of pairs in an array such that the highest power of 2 that divides their product is 1
- Highest power of a number that divides other number
- Minimum element whose n-th power is greater than product of an array of size n
- Smallest N digit number which is a perfect fourth power
- Smallest divisor D of N such that gcd(D, M) is greater than 1
- Smallest number greater or equals to N such that it has no odd positioned bit set
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.