Largest number up to N whose modulus with X is equal to Y modulo X | Function to print the largest number upto N whose modulus with X is same as Y % X ; Stores the required number ; Update num as the result ; Return the resultant number ; Driver code
function maximumNum ( X , Y , N ) { let num = 0 ; if ( N - N % X + Y <= N ) { num = N - N % X + Y ; } else { num = N - N % X - ( X - Y ) ; } return num ; } let X = 10 ; let Y = 5 ; let N = 15 ; document . write ( maximumNum ( X , Y , N ) ) ;