Count of pairs having even and odd LCM from an array | Java program to implement the above approach ; 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 ; Print the count of required pairs ; Driver Code
import java . util . * ; class GFG { static void LCMPairs ( int arr [ ] , int N ) { int total_pairs = ( N * ( N - 1 ) ) / 2 ; int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } odd = ( odd * ( odd - 1 ) ) / 2 ; System . out . println ( " Even ▁ = ▁ " + ( total_pairs - odd ) + " , ▁ Odd ▁ = ▁ " + odd ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 5 , 4 } ; int N = arr . length ; LCMPairs ( arr , N ) ; } }