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
< ? php function divSum ( $ n ) { $ sum = 1 ; for ( $ i = 2 ; $ i * $ i <= $ n ; $ i ++ ) if ( $ n % $ i == 0 ) $ sum = $ sum + $ i + floor ( $ n / $ i ) ; return $ sum ; } function areEquivalent ( $ num1 , $ num2 ) { return divSum ( $ num1 ) == divSum ( $ num2 ) ; } $ num1 = 559 ; $ num2 = 703 ; if ( areEquivalent ( $ num1 , $ num2 ) == true ) echo " Equivalent " ; else echo " Not ▁ Equivalent " ; ? >