Count of all possible pairs having sum of LCM and GCD equal to N | C ++ Program to implement the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int lcm ( int a , int b ) { return ( a * b ) / __gcd ( a , b ) ; } 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 ; } int main ( ) { int N = 14 ; cout << countPair ( N ) ; return 0 ; }