# BugCrush 2 Question 7 - BUGC207 - EDITORIAL

Author: codechefsrm
Editorialist : codechefsrm

EASY-MEDIUM

Mathematics,

## PROBLEM

Problem Description
Program to print the largest number up to N whose modulus with X is equal to Y modulo X.

Input:
No Input

Output:
15

Rules:
Bugs will be mainly logical errors, syntax errors etc. They are specific to C++ language.
Since it is a debugging contest, you will be provided with a bugged solution below the Constraints section. Please, see that you must adhere to the problem code
provided, make changes only where necessary.
Participants can copy the code and compile it using an online compiler (Eg. CodeChef IDE).
Once the bugs are eliminated from the code, the clean code should be submitted by using the “Submit” button on the top-right corner.
Participants will be penalised for changing the entire problem solution or writing their own solution, completely different from the buggy code as provided in the
problem statement as our main intention is to test the debugging abilities of the participants.

Buggy Code in C++:
Please copy the following code and paste it into your compiler for debugging.

``````#include <bits/stdc++.h>
using namespace std;
long long maximumNum(long A,long  B,long  C)
{
long num = 2;
if (C - C % A + B < C+A) {

num = C - C % A + B;
}
else {
num = C - C % A - (A - B);
}
return num;
}
int main()
{
long  A = 10;
long  B = 5;
long  C = 15;

cout << maximumNum(A, B);

return 0;
}
``````

## SOLUTION

``````#include <bits/stdc++.h>
using namespace std;
long long maximumNum(long long A,long long B,long long C)
{

long long num = 0;
if (C - C % A + B <= C) {
num = C - C % A + B;
}
else {
num = C - C % A - (A - B);
}

return num;
}
int main()
{
long long A = 10;
long long B = 5;
long long C = 15;
cout << maximumNum(A, B, C);
return 0;
}
``````