Given an integer N, the task is to find the summation of the harmonic series .
Input: N = 5
floor(3/1) + floor(3/2) + floor(3/3) = 3 + 1 + 1 = 5
Input: N = 20
Naive approach: Run a loop from 1 to N and find the summation of the floor values of N / i. Time complexiy of this approach will be O(n).
Efficient approach: Use the following formula to calculate the summation of the series:
Now, the loop needs to be run from 1 to sqrt(N) and the time complexity gets reduced to O(sqrt(N))
Below is the implementation of the above approach:
- Harmonic progression Sum
- Harmonic Progression
- Summation of GCD of all the pairs up to N
- Leibniz harmonic triangle
- Program for harmonic mean of numbers
- Series summation if T(n) is given and n is very large
- Program to find sum of harmonic series
- Program to find the Nth Harmonic Number
- Find Harmonic mean using Arithmetic mean and Geometric mean
- Find m-th summation of first n natural numbers.
- Geometric Progression
- Arithmetic Progression
- Sum of product of x and y such that floor(n/x) = y
- Program to print GP (Geometric Progression)
- Ratio of mth and nth term in an Arithmetic Progression (AP)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.