Summation of floor of harmonic progression | C # 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
using System ; class GFG { static double getSum ( int n ) { double sum = 0 ; int k = ( int ) Math . Sqrt ( n ) ; for ( int i = 1 ; i <= k ; i ++ ) { sum += Math . Floor ( ( double ) n / i ) ; } sum *= 2 ; sum -= Math . Pow ( k , 2 ) ; return sum ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( getSum ( n ) ) ; } }