Count of pairs ( i , j ) in the array such that arr [ i ] is a factor of arr [ j ] | Function to return the count of Pairs ; Driver code
function numPairs ( arr , n ) { let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) ans ++ ; } } return ans ; } let arr = [ 1 , 1 , 2 , 2 , 3 , 3 ] ; let n = arr . length ; document . write ( numPairs ( arr , n ) ) ;