Deficient Number | Function to calculate sum of divisors ; Initialize sum of prime factors ; Note that this loop runs till square root of n ; If divisors are equal , take only one of them ; Otherwise take both ; Function to check Deficient Number ; Check if sum ( n ) < 2 * n ; Driver Code
< ? php function divisorsSum ( $ 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 ) ; } } } return $ sum ; } function isDeficient ( $ n ) { return ( divisorsSum ( $ n ) < ( 2 * $ n ) ) ; } $ ds = isDeficient ( 12 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ; echo ( $ ds ) ; $ ds = isDeficient ( 15 ) ? " YES STRNEWLINE " : " NO STRNEWLINE " ; echo ( $ ds ) ; ? >