Find two numbers whose sum and GCD are given | C ++ program to find two numbers whose sum and GCD is given ; Function to find two numbers whose sum and gcd is given ; sum != gcd checks that both the numbers are positive or not ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void findTwoNumbers ( int sum , int gcd ) { if ( __gcd ( gcd , sum - gcd ) == gcd && sum != gcd ) cout << " a ▁ = ▁ " << min ( gcd , sum - gcd ) << " , ▁ b ▁ = ▁ " << sum - min ( gcd , sum - gcd ) << endl ; else cout << -1 << endl ; } int main ( ) { int sum = 8 ; int gcd = 2 ; findTwoNumbers ( sum , gcd ) ; return 0 ; }