Count of pairs having even and odd LCM from an array | Function to find count of distinct pairs having even LCM and odd LCM ; Store the total number of pairs ; Stores the count of odd numbers in the array ; Traverse the array arr ; Update the count of pairs with odd LCM ; Prvar the count of required pairs ; Driver Code
function LCMPairs ( arr , N ) { var total_pairs = ( N * ( N - 1 ) ) / 2 ; var odd = 0 ; for ( i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } odd = ( odd * ( odd - 1 ) ) / 2 ; document . write ( " " + ( total_pairs - odd ) + " " + odd ) ; } var arr = [ 3 , 6 , 5 , 4 ] ; var N = arr . length ; LCMPairs ( arr , N ) ;