Given a number n and a value k, the task is to find the smallest m(m>=n), such that m can be represented as a sum of distinct powers of k.
Input: n = 5, k = 5
Explanation: 5 = 51
Input: n = 29, k = 5
Explanation: 30 = 51 + 52
- Store the k-nary(base k) representation of n. Then traverse through each element of the base k representation.
- If the base k representation of this position is 1 or 0 then continue, if it is >1; it means that the current power of k occurs more than once.
- In that case, that power is added k (k’s-position value) times which makes it one power more (((k-1)+1).kx = k.kx = kx+1).
- Since the smallest number has to be found, after this step, all the lower powers of k is reduced to 0 as adding(k-b)kx (b=value at that position in base k representation) has already made the number bigger than the previous number.
- Finally, convert the number back to decimal form.
Below is the implementation of the above approach
- Smallest subarray of size greater than K with sum greater than a given value
- Highest and Smallest power of K less than and greater than equal to N respectively
- Length of longest subarray in which elements greater than K are more than elements not greater than K
- Check whether a number can be represented as sum of K distinct positive integers
- Smallest power of 4 greater than or equal to N
- Find the smallest positive number which can not be represented by given digits
- Largest number less than N with digit sum greater than the digit sum of N
- Smallest number greater than or equal to X whose sum of digits is divisible by Y
- Smallest number greater than Y with sum of digits equal to X
- Count the number of words having sum of ASCII values less than and greater than k
- Highest power of 2 that divides a number represented in binary
- Minimum element whose n-th power is greater than product of an array of size n
- Smallest subarray with sum greater than a given value
- Smallest subset with sum greater than all other elements
- Length of Smallest subarray in range 1 to N with sum greater than a given value
- Length of Smallest Subsequence such that sum of elements is greater than equal to K
- Smallest subarray from a given Array with sum greater than or equal to K
- Smallest subarray from a given Array with sum greater than or equal to K | Set 2
- Check if given number can be represented as sum of two great numbers
- Check whether a number can be represented by sum of two squares
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.