VOOZH about

URL: https://www.geeksforgeeks.org/dsa/sum-series-n1-n2-n3-n4-nn/

⇱ Sum of series (n/1) + (n/2) + (n/3) + (n/4) +.......+ (n/n) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Sum of series (n/1) + (n/2) + (n/3) + (n/4) +.......+ (n/n)

Last Updated : 11 Aug, 2022

Given a value n, find the sum of series, (n/1) + (n/2) + (n/3) + (n/4) +.......+(n/n) where the value of n can be up to 10^12. 
Note: Consider only integer division.
Examples: 
 

Input : n = 5
Output : (5/1) + (5/2) + (5/3) + 
 (5/4) + (5/5) = 5 + 2 + 1 + 1 + 1 
 = 10

Input : 7
Output : (7/1) + (7/2) + (7/3) + (7/4) +
 (7/5) + (7/6) + (7/7) 
 = 7 + 3 + 2 + 1 + 1 + 1 + 1 
 = 16


 


Below is the program to find the sum of given series: 
 

Output: 
 

131

Time complexity: O(sqrt(n)) as for loop will run by sqrt(n) times

Auxiliary Space: O(1)
Note: If observed closely, we can see that, if we take n common, series turns into an Harmonic Progression.
 

Comment