Maximum count of pairwise co | Function to find the gcd of two numbers ; Function to of pairwise co - prime and common divisors of two numbers ; Initialize answer with 1 , to include 1 in the count ; Count of primes of gcd ( N , M ) ; Finding prime factors of gcd ; Increment count if it is divisible by i ; Return the total count ; Function Call for each pair to calculate the count of pairwise co - prime divisors ; Given array of pairs ; Function Call
function gcd ( x , y ) { if ( x % y == 0 ) return y ; else return gcd ( y , x % y ) ; } function countPairwiseCoprime ( N , M ) { let answer = 1 ; let g = gcd ( N , M ) ; let temp = g ; for ( let i = 2 ; i * i <= g ; i ++ ) { if ( temp % i == 0 ) { answer ++ ; while ( temp % i == 0 ) temp /= i ; } } if ( temp != 1 ) answer ++ ; return answer ; } function countCoprimePair ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { document . write ( countPairwiseCoprime ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) + " " ) ; } } let arr = [ [ 12 , 18 ] , [ 420 , 660 ] ] ; let N = arr . length ; countCoprimePair ( arr , N ) ;