Check if a given pair of Numbers are Betrothed numbers or not | Function to check whether N is Perfect Square or not ; Find sqrt ; Function to check whether the given pairs of numbers is Betrothed Numbers or not ; For finding the sum of all the divisors of first number n ; For finding the sum of all the divisors of second number m ; Driver Code ; Function Call
function isPerfectSquare ( N ) { let sr = Math . sqrt ( N ) ; return ( sr - Math . floor ( sr ) ) == 0 ; } function BetrothedNumbers ( n , m ) { let Sum1 = 1 ; let Sum2 = 1 ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { Sum1 += i + ( isPerfectSquare ( n ) ? 0 : parseInt ( n / i ) ) ; } } for ( let i = 2 ; i <= Math . sqrt ( m ) ; i ++ ) { if ( m % i == 0 ) { Sum2 += i + ( isPerfectSquare ( m ) ? 0 : parseInt ( m / i ) ) ; } } if ( ( n + 1 == Sum2 ) && ( m + 1 == Sum1 ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } let N = 9504 ; let M = 20734 ; BetrothedNumbers ( N , M ) ;