Superperfect Number | Function to calculate sum of all divisors ; Final result of summation of divisors ; 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 ; Returns true if n is Super Perfect else false . ; Find the sum of all divisors of number n ; Again find the sum of all divisors of n1 and check if sum is equal to n1 ; Driver Code
function divSum ( num ) { let result = 0 ; for ( let i = 1 ; i * i <= num ; ++ i ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return result ; } function isSuperPerfect ( n ) { let n1 = divSum ( n ) ; return ( 2 * n == divSum ( n1 ) ) ; } let n = 16 ; document . write ( ( isSuperPerfect ( n ) ? " " : " " ) + " " ) ; n = 6 ; document . write ( ( isSuperPerfect ( n ) ? " " : " " ) + " " ) ;