Count of quadruples with product of a pair equal to the product of the remaining pair | Function to count the number of unique quadruples from an array that satisfies the given condition ; Hashmap to store the product of pairs ; Store the count of required quadruples ; Traverse the array arr [ ] and generate all possible pairs ; Store their product ; Pair ( a , b ) can be used to generate 8 unique permutations with another pair ( c , d ) ; Increment um [ prod ] by 1 ; Print the result ; Driver Code
function sameProductQuadruples ( nums , N ) { var umap = new Array ( 10000 ) . fill ( 0 ) ; var res = 0 ; for ( var i = 0 ; i < N ; ++ i ) { for ( var j = i + 1 ; j < N ; ++ j ) { var prod = nums [ i ] * nums [ j ] ; res += 8 * umap [ prod ] ; ++ umap [ prod ] ; } } document . write ( res ) ; } var arr = [ 2 , 3 , 4 , 6 ] ; var N = arr . length ; sameProductQuadruples ( arr , N ) ;