Summation of floor of harmonic progression | Python3 implementation of the approach ; 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
from math import floor , sqrt , ceil NEW_LINE def getSum ( n ) : NEW_LINE INDENT summ = 0 NEW_LINE k = ( n ) ** ( .5 ) NEW_LINE for i in range ( 1 , floor ( k ) + 1 ) : NEW_LINE INDENT summ += floor ( n / i ) NEW_LINE DEDENT summ *= 2 NEW_LINE summ -= pow ( floor ( k ) , 2 ) NEW_LINE return summ NEW_LINE DEDENT n = 5 NEW_LINE print ( getSum ( n ) ) NEW_LINE