Count pairs from an array having equal sum and quotient | Function to count all pairs ( i , j ) such that a [ i ] + [ j ] = a [ i ] / a [ j ] ; Stores total count of pairs ; Generate all possible pairs ; If a valid pair is found ; Increment count ; Return the final count ; Driver Code
def countPairs ( a , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( a [ j ] != 0 and a [ i ] % a [ j ] == 0 ) : NEW_LINE INDENT if ( ( a [ i ] + a [ j ] ) == ( a [ i ] // a [ j ] ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 4 , - 3 , 0 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countPairs ( arr , N ) ) NEW_LINE DEDENT