Count of all possible pairs having sum of LCM and GCD equal to N | Java program to implement the above approach ; 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
class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static int lcm ( int a , int b ) { return ( a * b ) / __gcd ( a , b ) ; } static int countPair ( int N ) { int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { if ( __gcd ( i , j ) + lcm ( i , j ) == N ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int N = 14 ; System . out . print ( countPair ( N ) ) ; } }