Count of all possible pairs having sum of LCM and GCD equal to N | Recursive function to return gcd of a and b ; Function to calculate and return LCM of two numbers ; Function to count pairs whose sum of GCD and LCM is equal to N ; Driver Code
function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } function lcm ( a , b ) { return ( a * b ) / __gcd ( a , b ) ; } function countPair ( N ) { var count = 0 ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { if ( __gcd ( i , j ) + lcm ( i , j ) == N ) { count ++ ; } } } return count ; } var N = 14 ; document . write ( countPair ( N ) ) ;