Abundant Number | Function to calculate sum of divisors ; Note that this loop runs till square root of n ; If divisors are equal , take only one of them ; Otherwise take both ; calculate sum of all proper divisors only ; Function to check Abundant Number ; Return true if sum of divisors is greater than n . ; Driver Code
< ? php function getSum ( $ n ) { $ sum = 0 ; for ( $ i = 1 ; $ i <= sqrt ( $ n ) ; $ i ++ ) { if ( $ n % $ i == 0 ) { if ( $ n / $ i == $ i ) $ sum = $ sum + $ i ; else { $ sum = $ sum + $ i ; $ sum = $ sum + ( $ n / $ i ) ; } } } $ sum = $ sum - $ n ; return $ sum ; } function checkAbundant ( $ n ) { return ( getSum ( $ n ) > $ n ) ; } $ k = checkAbundant ( 12 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ; echo ( $ k ) ; $ k = checkAbundant ( 15 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ; echo ( $ k ) ; ? >