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
- Harmonic progression Sum
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Leibniz harmonic triangle
- Program for harmonic mean of numbers
- Find Harmonic mean using Arithmetic mean and Geometric mean
- Program to find the Nth Harmonic Number
- Program to find sum of harmonic series
- Summation of GCD of all the pairs up to N
- Series summation if T(n) is given and n is very large
- 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
- 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 email@example.com. 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.