Count all distinct pairs with product equal to K | Function to count the number of pairs whose product is equal to K ; Pick all elements one by one ; Check if the product of this pair is equal to K ; Driver code
function countPairsWithProdK ( arr , n , k ) { var count = 0 ; for ( var i = 0 ; i < n ; i ++ ) { for ( var j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] * arr [ j ] == k ) count ++ ; } return count ; } var arr = [ 1 , 5 , 3 , 4 , 2 ] ; var N = arr . length ; var K = 3 ; document . write ( countPairsWithProdK ( arr , N , K ) ) ;