Sum of all divisors from 1 to n | Utility function to find sum of all divisor of number up to ' n ' ; Driver code
function divisorSum ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; ++ i ) sum += Math . floor ( n / i ) * i ; return sum ; } let n = 4 ; document . write ( divisorSum ( n ) + " " ) ; n = 5 ; document . write ( divisorSum ( n ) + " " ) ;