Count of quadruples with product of a pair equal to the product of the remaining pair | Java program for the above approach ; 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
import java . io . * ; import java . util . * ; class GFG { static void sameProductQuadruples ( int [ ] nums , int N ) { int [ ] umap = new int [ 10000 ] ; int res = 0 ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = i + 1 ; j < N ; ++ j ) { int prod = nums [ i ] * nums [ j ] ; res += 8 * umap [ prod ] ; ++ umap [ prod ] ; } } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 6 } ; int N = arr . length ; sameProductQuadruples ( arr , N ) ; } }