Admirable Numbers | Function to calculate the sum of all 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 ; Add 1 and n to result as above loop considers proper divisors greater ; Function to check if there exists a proper divisor D ' ▁ of ▁ N ▁ such ▁ that ▁ sigma ( n ) -2D ' = 2 N ; 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 ; Check 1 since 1 is also a divisor ; Function to check if N is an admirable number ; Driver code
function divSum ( n ) { let result = 0 ; for ( let i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + n + 1 ) ; } function check ( num ) { let sigmaN = divSum ( num ) ; for ( let i = 2 ; i <= Math . sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) { if ( sigmaN - 2 * i == 2 * num ) return true ; } else { if ( sigmaN - 2 * i == 2 * num ) return true ; if ( sigmaN - 2 * ( num / i ) == 2 * num ) return true ; } } } if ( sigmaN - 2 * 1 == 2 * num ) return true ; return false ; } function isAdmirableNum ( N ) { return check ( N ) ; } let n = 12 ; if ( isAdmirableNum ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;