Sum of series ( n / 1 ) + ( n / 2 ) + ( n / 3 ) + ( n / 4 ) + ... ... . + ( n / n ) | Java program to find sum of given series ; function to find sum of series ; Driver code
import java . util . * ; class GFG { static long sum ( long n ) { long root = ( long ) Math . sqrt ( n ) ; long ans = 0 ; for ( int i = 1 ; i <= root ; i ++ ) ans += n / i ; ans = 2 * ans - ( root * root ) ; return ans ; } public static void main ( String [ ] args ) { long n = 35 ; System . out . println ( sum ( n ) ) ; } }