Find two numbers whose sum and GCD are given | function to find gcd of two numbers ; Function to find two numbers whose sum and gcd is given ; sum != gcd checks that both the numbers are positive or not ; Driver code
function __gcd ( a , b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } function findTwoNumbers ( sum , gcd ) { if ( __gcd ( gcd , sum - gcd ) == gcd && sum != gcd ) document . write ( " " + Math . min ( gcd , sum - gcd ) + " " + ( sum - Math . min ( gcd , sum - gcd ) ) ) ; else document . write ( - 1 ) ; } let sum = 8 ; let gcd = 2 ; findTwoNumbers ( sum , gcd ) ;