Deficient 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 ; else Otherwise take both ; Function to check Deficient Number ; Check if sum ( n ) < 2 * n ; Driver code to test above methods
function divisorsSum ( n ) { for ( let i = 1 ; i <= ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { sum = sum + i ; } { sum = sum + i ; sum = sum + ( n / i ) ; } } } return sum ; } function isDeficient ( n ) { return ( divisorsSum ( n ) < ( 2 * n ) ) ; } if ( isDeficient ( 12 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; if ( isDeficient ( 15 ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;