We are given a number n, we need to find the maximum sum possible with the help of following function:
F(n) = max( (F(n/2) + F(n/3) + F(n/4) + F(n/5)), n). To calculate F(n, ) we may either have n as our result or we can further break n into four part as in given function definition. This can be done as much time as we can. Find the maximum possible sum you can get from a given N. Note : 1 can not be break further so F(1) = 1 as a base case.
Input : n = 10 Output : MaxSum = 12 Explanation: f(10) = f(10/2) + f(10/3) + f(10/4) + f(10/5) = f(5) + f(3) + f(2) + f(2) = 12 5, 3 and 2 cannot be further divided. Input : n = 2 Output : MaxSum = 2
Approach : This problem can be solve with recursive approach but that will cost us a high complexity because of its overlapping sub problems. So we apply dynamic programming concept to solve this question in bottom up manner as:
MaxSum = 106
- Maximum sum after repeatedly dividing N by a divisor
- Choice of Area
- Longest dividing subsequence
- Count of divisors having more set bits than quotient on dividing N
- Ways of dividing a group into two halves such that two elements are in different groups
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Count number of digits after decimal on dividing a number
- Maximum value of |arr[i] - arr[j]| + |i - j|
- Find maximum among x^(y^2) or y^(x^2) where x and y are given
- Find maximum value of x such that n! % (k^x) = 0
- Maximum value of |arr - arr| + |arr - arr| + ... +|arr[n - 2] - arr[n - 1]| when elements are from 1 to n
- Pair with maximum GCD from two arrays
- Maximum GCD of N integers with given product
- Maximum Primes whose sum is equal to given N
- Maximum array sum that can be obtained after exactly k changes
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.
Improved By : jit_t