Maximum possible sum of K even multiples of 5 in a given range | Function to find the maximum sum of K even multiples of 5 in the range [ L , R ] ; Store the total number of even multiples of 5 in the range [ L , R ] ; Check if K > N ; If true , print - 1 and return ; Otherwise , divide R by 10 ; Store the sum using the formula ; Print the sum ; Given L , R and K ; Function Call
function maxksum ( L , R , K ) { let N = ( R / 10 - L / 10 ) + 1 ; if ( K > N ) { document . write ( " " ) ; return ; } R = R / 10 ; let X = R - K ; let sum = 10 * ( ( R * ( R + 1 ) ) / 2 - ( X * ( X + 1 ) ) / 2 ) ; document . write ( sum ) ; } let L = 16 , R = 60 , K = 4 ; maxksum ( L , R , K ) ;