GCDChel Loves GCD
Time limit1sMemory limit1024 MB
Given an array, repeatedly split off either the left floor(n/2) elements or the right ceil(n/2) elements, sum the GCDs of the removed blocks, and maximize that sum.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Math, Number theory
- Solved
- No attempts yet
Problem
Sicheol wants to find the most beautiful studio apartment in Sinchon. Too busy to visit rooms in person, he plans to predict a studio's beauty from its listing number and the greatest common divisor (GCD). The beauty is computed as follows.
- There is an integer array of listing numbers. (, where is the number of elements of )
- Choose elements from the left of , or elements from the right. If has exactly one element, choose that element.
- Compute the of the chosen elements.
- Let be the array of elements not chosen, and repeat from step 2.
- The beauty of the studio is the maximum possible sum of the values obtained in step 3.
Compute the beauty of the studio from the listing numbers!
Input
The first line gives an integer . ()
The second line gives integers , the listing numbers of the studio. ()
Output
Print the beauty of the studio.