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 sub-array sum after dividing array into sub-arrays based on the given queries
- Check if there exists a prime number which gives Y after being repeatedly subtracted from X
- Count subarrays such that remainder after dividing sum of elements by K gives count of elements
- Count number of digits after decimal on dividing a number
- Number formed after K times repeated addition of smallest divisor of N
- Minimize array length by repeatedly replacing pairs of unequal adjacent array elements by their sum
- Largest number in given Array formed by repeatedly combining two same elements
- Check whether an Array can be made 0 by splitting and merging repeatedly
- Array value by repeatedly replacing max 2 elements with their absolute difference
- Minimize Array length by repeatedly replacing co-prime pairs with 1
- Maximum value with the choice of either dividing or considering as it is
- Largest number dividing maximum number of elements in the array
- Sum of greatest odd divisor of numbers in given range
- Minimize sum by dividing all elements of a subarray by K
- Smallest number to make Array sum at most K by dividing each element
- Sum of largest divisor of numbers upto N not divisible by given prime number P
- Greatest divisor which divides all natural number in range [L, R]
- Max occurring divisor in an interval
- Count of divisors having more set bits than quotient on dividing N
- Smallest divisor D of N such that gcd(D, M) is greater than 1
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.