Maximum sum of distinct numbers such that LCM of these numbers is N | Returns maximum sum of numbers with LCM as N ; Finding a divisor of n and adding it to max_sum ; Driver code
function maxSumLCM ( n ) { for ( let i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { max_sum += i ; if ( n / i != i ) max_sum += ( n / i ) ; } } return max_sum ; } let n = 2 ; document . write ( maxSumLCM ( n ) + " " ) ;