Maximum sum of distinct numbers such that LCM of these numbers is N | Java 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 ; main function
class MaxSum { static 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 ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( maxSumLCM ( n ) ) ; } }