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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Harmonic progression Sum
- Harmonic Progression
- Check whether nodes of Binary Tree form Arithmetic, Geometric or Harmonic Progression
- Program for harmonic mean of numbers
- Find Harmonic mean using Arithmetic mean and Geometric mean
- Leibniz harmonic triangle
- Program to find the Nth Harmonic Number
- Program to find sum of harmonic series
- Summation of GCD of all the pairs up to N
- Find m-th summation of first n natural numbers.
- Series summation if T(n) is given and n is very large
- Sum of product of x and y such that floor(n/x) = y
- Minimum number of square tiles required to fill the rectangular floor
- Floor square root without using sqrt() function : Recursive
- All possible values of floor(N/K) for all values of K
- Floor value Kth root of a number using Recursive Binary Search
- Maximum number of tiles required to cover the floor of given size using 2x1 size tiles
- Find the missing number in Arithmetic Progression
- Removing a number from array to make it Geometric Progression
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.