Largest number up to N whose modulus with X is equal to Y modulo X | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; long long maximumNum ( long long X , long long Y , long long N ) { long long num = 0 ; if ( N - N % X + Y <= N ) { num = N - N % X + Y ; } else { num = N - N % X - ( X - Y ) ; } return num ; } int main ( ) { long long X = 10 ; long long Y = 5 ; long long N = 15 ; cout << maximumNum ( X , Y , N ) ; return 0 ; }