Check if sum of divisors of two numbers are same | Function to calculate sum of all proper divisors num -- > given natural number ; To store sum of divisors ; Find all divisors and add them ; Function to check if both numbers are equivalent or not ; Driver code
function divSum ( n ) { let sum = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) if ( n % i == 0 ) sum = sum + i + parseInt ( n / i , 10 ) ; return sum ; } function areEquivalent ( num1 , num2 ) { return divSum ( num1 ) == divSum ( num2 ) ; } let num1 = 559 ; let num2 = 703 ; if ( areEquivalent ( num1 , num2 ) ) document . write ( " " ) ; else document . write ( " " ) ;