https://www.geeksforgeeks.org/minimum-sum-of-the-elements-of-an-array-after-subtracting-smaller-elements-from-larger/
Given an array arr, the task is to find the minimum sum of the elements of the array after applying the following operation:
For any pair from the array, if a[i] > a[j] then a[i] = a[i] – a[j].
For any pair from the array, if a[i] > a[j] then a[i] = a[i] – a[j].
Examples:
Input: arr[] = {1, 2, 3}
Output: 3
modified array will be {1, 1, 1}Input: a = {2, 4, 6}
Output: 6
modified array will be {2, 2, 2}
Approach: Observe here that after each operation, the GCD of all the elements will remain the same. So, in the end, every element will be equal to the gcd of all the elements of the array after applying the given operation.
So, the final answer will be (n * gcd).
So, the final answer will be (n * gcd).