Given an integer N. The task is to find the maximum possible sum of intermediate values (Including N and 1) attained after applying the beow operation:
Divide N by any divisor (>1) until it becomes 1.
Input: N = 10 Output: 16 Initially, N=10 1st Division -> N = 10/2 = 5 2nd Division -> N= 5/5 = 1 Input: N = 8 Output: 15 Initially, N=8 1st Division -> N = 8/2 = 4 2nd Division -> N= 4/2 = 2 3rd Division -> N= 2/2 = 1
Approach: Since the task is to maximize the sum of values after each step, try to maximize individual values. So, reduce the value of N by as little as possible. To achieve that, we divide N by its smallest divisor.
Below is the implementation of the above approach:
Time Complexity: O(sqrt(n)*log(n))
- Maximum value with the choice of either dividing or considering as it is
- Largest number dividing maximum number of elements in the array
- Maximum sub-array sum after dividing array into sub-arrays based on the given queries
- Array value by repeatedly replacing max 2 elements with their absolute difference
- Check whether an Array can be made 0 by splitting and merging repeatedly
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
- Largest number in given Array formed by repeatedly combining two same elements
- Max occurring divisor in an interval
- Smallest divisor D of N such that gcd(D, M) is greater than 1
- Smallest prime divisor of a number
- Sum of greatest odd divisor of numbers in given range
- Generating numbers that are divisor of their right-rotations
- Find the k-th smallest divisor of a natural number N
- Find an integer X which is divisor of all except exactly one element in an array
- Largest Divisor for each element in an array other than 1 and the number itself
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.