Sum of all proper divisors from 1 to N | Utility function to find sum of all proper divisor of number up to N ; Loop to find the proper divisor of every number from 1 to N ; Driver Code
function properDivisorSum ( n ) { var sum = 0 ; for ( var i = 1 ; i <= n ; ++ i ) sum += parseInt ( n / i ) * i ; return sum - n * ( ( n + 1 ) / 2 ) ; } var n = 4 ; document . write ( properDivisorSum ( n ) + " " ) ; n = 5 ; document . write ( properDivisorSum ( n ) + " " ) ;