Sum of product of x and y such that floor ( n / x ) = y | Return the sum of natural number in a range . ; n * ( n + 1 ) / 2. ; Return the sum of product x * y . ; Iterating i from 1 to sqrt ( n ) ; Finding the upper limit . ; Finding the lower limit . ; Driver Code
function sumOfRange ( a , b ) { let i = ( a * ( a + 1 ) ) >> 1 ; let j = ( b * ( b + 1 ) ) >> 1 ; return ( i - j ) ; } function sumofproduct ( n ) { let sum = 0 ; let root = Math . floor ( Math . sqrt ( n ) ) ; for ( let i = 1 ; i <= root ; i ++ ) { let up = Math . floor ( n / i ) ; let low = Math . max ( Math . floor ( n / ( i + 1 ) ) , root ) ; sum += ( i * sumOfRange ( up , low ) ) ; sum += ( i * Math . floor ( n / i ) ) ; } return sum ; } let n = 10 ; document . write ( sumofproduct ( n ) ) ;