Maximum sum of distinct numbers with LCM as N | Java program to get maximum sum of Numbers with condition that their LCM should be N ; Method returns maximum sum f distinct number whose LCM is N ; find all divisors which divides ' N ' ; if ' i ' is divisor of ' N ' ; if both divisors are same then add it only once else add both ; Driver code
class GFG { static int getMaximumSumWithLCMN ( int N ) { int sum = 0 ; int LIM = ( int ) Math . sqrt ( N ) ; for ( int i = 1 ; i <= LIM ; i ++ ) { if ( N % i == 0 ) { if ( i == ( N / i ) ) sum += i ; else sum += ( i + N / i ) ; } } return sum ; } public static void main ( String [ ] args ) { int N = 12 ; System . out . println ( getMaximumSumWithLCMN ( N ) ) ; } }