Count pairs from an array having equal sum and quotient | C # program for the above approach ; Function to find number of pairs with equal sum and quotient from a given array ; Store the count of pairs ; Stores frequencies ; Traverse the array ; If y is neither 1 or 0 ; Evaluate x ; Increment count by frequency of x ; Update map ; Print the final count ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int countPairs ( int [ ] a , int n ) { int count = 0 ; Dictionary < double , int > mp = new Dictionary < double , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int y = a [ i ] ; if ( y != 0 && y != 1 ) { double x = ( ( y * 1.0 ) / ( 1 - y ) ) * y ; if ( ! mp . ContainsKey ( x ) ) mp [ x ] = 0 ; count += mp [ x ] ; } if ( ! mp . ContainsKey ( y ) ) mp [ y ] = 0 ; mp [ y ] ++ ; } return count ; } public static void Main ( ) { int [ ] arr = { - 4 , - 3 , 0 , 2 , 1 } ; int N = arr . Length ; Console . Write ( countPairs ( arr , N ) ) ; } }