Problem Statement :
We have to add different numbers(could be 0 too) to elements of a set so that gcd of all elements becomes greater than 1 and the set is arranged in ascending order.
Example : Set S = {5,4,7,6,8}
Now the best alteration to fit the above condition will lead to => {6,6,8,8,8}
So the answer will be 1+2+1+2+0 = 6
Till now I've done this :
Change the elements such that the set becomes sorted.
A0<=A1<=A2<=A3<=...<=An
Now if the set contains two or more distinct primes, increment all of them by 1.
Now, I thought seeing that if there are more even numbers than odd, then least sum would be equal to number of odd elements(each incremented by 1).
But I was wrong as : if S = {5,10,15,20,24} answer would be 1 (changing 24 to 25).
How should I tackle this problem ?