Primitive Abundant Number | Function to 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 ; Function to check Abundant Number ; Return true if sum of divisors is greater than N . ; Function to check Deficient Number ; Check if sum ( n ) < 2 * n ; Function to check all proper divisors of N is deficient number or not ; If number itself is not abundant retuen false ; Find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Driver Code
function getSum ( n ) { let sum = 0 ; for ( let i = 1 ; i <= Math . 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 checkAbundant ( n ) { return ( getSum ( n ) - n > n ) ; } function isDeficient ( n ) { return ( getSum ( n ) < ( 2 * n ) ) ; } function checkPrimitiveAbundant ( num ) { if ( ! checkAbundant ( num ) ) { return false ; } for ( let i = 2 ; i <= Math . sqrt ( num ) ; i ++ ) { if ( num % i == 0 && i != num ) { if ( i * i == num ) { if ( ! isDeficient ( i ) ) { return false ; } } else if ( ! isDeficient ( i ) || ! isDeficient ( num / i ) ) { return false ; } } } return true ; } let n = 20 ; if ( checkPrimitiveAbundant ( n ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }