Computer Science, asked by stepheneliazer18, 11 months ago

You are given three numbers, "a", "b", and "c". Write a program to determine the largest number that is less than or equal to "c" and leaves a remainder "b" when divided by "a".
Input:
First line: "t" denoting number of test cases.Each of the next "t" lines : Three space-seperated integers denoting the values "a", "b", "c" respectively .
Output:
Print the required answer for each test case in a new line. If no such number exists, then print "-1".
Note: The output cannot be negative. Result can be a big integer, So return modulus of 10^9
Sample Input 1:
2
3 2 9
1 2 4
Sample Output 1:
8
-1

Answers

Answered by poonam099
14

Answer:

Explanation:

#include <bits/stdc++.h>

using namespace std;

int main() {

// your code goes here

long long t,a,b,c;

cin>>t;

while(t--)

{

 cin>>a>>b>>c;

    long long ans=0;

    long long x = c%a;

    long long y =(c-b)%a;

  if(x>b)ans = c - (x-b);

  else

  {

   ans =  c - y ;

  }

cout<<ans<<endl;

}

return 0;

}

Answered by AneesKakar
0

Objective:

Write a program to determine the largest number that is less than or equal to "c" and leaves a remainder "b" when divided by "a".

Solution:

#include <bits/stdc++.h>

using namespace std;

int main() {

// your code goes here

long long t,a,b,c;

cin>>t;

while(t--)

{

cin>>a>>b>>c;

   long long ans=0;

   long long x = c%a;

   long long y =(c-b)%a;

 if(x>b)ans = c - (x-b);

 else

 {

  ans =  c - y ;

 }

cout<<ans<<endl;

}

return 0;

}


#SPJ3

Similar questions