Summation of floor of harmonic progression | Function to return the summation of the given harmonic series ; To store the summation ; Floor of sqrt ( n ) ; Summation of floor ( n / i ) ; From the formula ; Driver code
function getSum ( n ) { let sum = 0 ; let k = parseInt ( Math . sqrt ( n ) ) ; for ( let i = 1 ; i <= k ; i ++ ) { sum += Math . floor ( n / i ) ; } sum *= 2 ; sum -= Math . pow ( k , 2 ) ; return sum ; } let n = 5 ; document . write ( getSum ( n ) ) ;