Superabundant 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 both ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Function to check if N is a superabundant number ; to check all numbers from 1 to N ; Driver code
function sigma ( n ) { if ( n == 1 ) return 1 ; var result = 0 ; for ( var 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 isSuperabundant ( N ) { for ( var i = 1 ; i < N ; i ++ ) { var x = sigma ( i ) / i ; var y = sigma ( N ) / ( N * 1.0 ) ; if ( x > y ) return false ; } return true ; } var N = 4 ; isSuperabundant ( N ) ? document . write ( " " ) : document . write ( " " ) ;