AmazonOA #292
Minimize Effort with EffiBin Kit
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & MathHashing
In each step, choose two positions i and j; if the current effort[i] is divisible by the current effort[j], change effort[i] to effort[j]. You may do this any number of times, or not at all. The goal is to minimize the sum of the final array. The operation does not divide i by j; it replaces i directly with the current value of j.
Input
The first line contains n and the second line contains effort. 1≤n≤200000, 1≤effort[i]≤200000.
Output
Output a single integer, the answer.
Example 1
Input:
5
3 6 2 5 25
Output:
17
Example 2
Input:
3
6 10 15
Output:
31
Example 3
Input:
3
2 4 8
Output:
6
Example notes
The answers are 17, 31 and 6 respectively. In the second example no value is divisible by any other, smaller original value, so values cannot simply become the common factor 1.
Editorial
Loading solution…