Maximum sum of distinct numbers with LCM as 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 to test above methods
function getMaximumSumWithLCMN ( N ) { let sum = 0 ; let LIM = Math . sqrt ( N ) ; for ( let i = 1 ; i <= LIM ; i ++ ) { if ( N % i == 0 ) { if ( i == ( N / i ) ) sum += i ; else sum += ( i + N / i ) ; } } return sum ; } let N = 12 ; document . write ( getMaximumSumWithLCMN ( N ) + " " ) ;