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 ; Initialize result ; Finding a divisor of n and adding it to max_sum ; Driver Code
using System ; class MaxSum { static int maxSumLCM ( int n ) { int max_sum = 0 ; 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 ; } public static void Main ( String [ ] args ) { int n = 2 ; Console . Write ( maxSumLCM ( n ) ) ; } }