Check for Amicable Pair | Function to calculate sum of all proper divisors of a given number ; Sum of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' n ' ; if both divisors are same then add it once else add both ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Returns true if x and y are Amicable else false . ; Driver Code
< ? php function divSum ( $ n ) { $ result = 0 ; for ( $ i = 2 ; $ i <= sqrt ( $ n ) ; $ i ++ ) { if ( $ n % $ i == 0 ) { if ( $ i == ( $ n / $ i ) ) $ result += $ i ; else $ result += ( $ i + $ n / $ i ) ; } } return ( $ result + 1 ) ; } function areAmicable ( $ x , $ y ) { if ( divSum ( $ x ) != $ y ) return false ; return ( divSum ( $ y ) == $ x ) ; } $ x = 220 ; $ y = 284 ; if ( areAmicable ( $ x , $ y ) ) echo " Yes " ; else echo " No " ; ? >