Count pairs from an array having GCD equal to the minimum element in the pair | Function to count pairs from an array having GCD equal to minimum element of that pair ; Stores the resultant count ; Iterate over the range [ 0 , N - 2 ] ; Iterate over the range [ i + 1 , N ] ; If arr [ i ] % arr [ j ] is 0 or arr [ j ] % arr [ i ] is 0 ; Increment count by 1 ; Return the resultant count ; Driver Code
def countPairs ( arr , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , N ) : NEW_LINE INDENT if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 1 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countPairs ( arr , N ) ) NEW_LINE DEDENT