Sum of series ( n / 1 ) + ( n / 2 ) + ( n / 3 ) + ( n / 4 ) + ... ... . + ( n / n ) | CPP program to find sum of given series ; function to find sum of series ; driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long int sum ( long long int n ) { long long int root = sqrt ( n ) ; long long int ans = 0 ; for ( int i = 1 ; i <= root ; i ++ ) ans += n / i ; ans = 2 * ans - ( root * root ) ; return ans ; } int main ( ) { long long int n = 35 ; cout << sum ( n ) ; return 0 ; }