Maximum number which can divide all array element after one replacement | Function to return gcd1 of two numbers ; If one of numbers is 0 then gcd1 is other number ; If both are equal then that value is gcd1 ; One is greater ; Function to return minimum sum ; Initialize min_sum with large value ; Initialize variable gcd1 ; Storing value of arr [ i ] in c ; Update maxgcd1 if gcd1 is greater than maxgcd1 ; returning the maximum divisor of all elements ; Driver code
def gcd1OfTwoNos ( num1 , num2 ) : NEW_LINE INDENT if ( num1 == 0 ) : NEW_LINE INDENT return num2 NEW_LINE DEDENT if ( num2 == 0 ) : NEW_LINE INDENT return num1 NEW_LINE DEDENT if ( num1 == num2 ) : NEW_LINE INDENT return num1 NEW_LINE DEDENT if ( num1 > num2 ) : NEW_LINE INDENT return gcd1OfTwoNos ( num1 - num2 , num2 ) NEW_LINE DEDENT return gcd1OfTwoNos ( num1 , num2 - num1 ) NEW_LINE DEDENT def Min_sum ( arr , N ) : NEW_LINE INDENT min_sum = 1000000 NEW_LINE maxgcd1 = 1 NEW_LINE for i in range ( N ) : NEW_LINE INDENT gcd1 = 1 NEW_LINE if ( i == 0 ) : NEW_LINE INDENT gcd1 = arr [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT gcd1 = arr [ i - 1 ] NEW_LINE DEDENT for j in range ( N ) : NEW_LINE INDENT if ( j != i ) : NEW_LINE INDENT gcd1 = gcd1OfTwoNos ( gcd1 , arr [ j ] ) NEW_LINE DEDENT DEDENT c = arr [ i ] NEW_LINE if ( gcd1 > maxgcd1 ) : NEW_LINE INDENT maxgcd1 = gcd1 NEW_LINE DEDENT DEDENT return maxgcd1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 16 , 5 , 10 , 25 ] NEW_LINE N = len ( arr ) NEW_LINE print ( Min_sum ( arr , N ) ) NEW_LINE DEDENT