Largest number up to N whose modulus with X is equal to Y modulo X | Java program for the above approach ; 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
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static long maximumNum ( long X , long Y , long N ) { long num = 0 ; if ( N - N % X + Y <= N ) { num = N - N % X + Y ; } else { num = N - N % X - ( X - Y ) ; } return num ; } public static void main ( String [ ] args ) { long X = 10 ; long Y = 5 ; long N = 15 ; System . out . println ( maximumNum ( X , Y , N ) ) ; } }