Maximum sum of distinct numbers such that LCM of these numbers is N | C ++ program to find the max sum of numbers whose lcm is n ; Returns maximum sum of numbers with LCM as N ; Finding a divisor of n and adding it to max_sum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int maxSumLCM ( int n ) { for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { max_sum += i ; if ( n / i != i ) max_sum += ( n / i ) ; } } return max_sum ; } int main ( ) { int n = 2 ; cout << MaxSumLCM ( n ) << endl ; return 0 ; }