Divisional
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
Wh
Cesta
Input format
• First line: t denoting the number of test cases
. Each of the next t lines: Three space-separated
values of
b, and c
Output format
Print the required answer for each test
Answers
Answer:
a is equal to / less than c
c/a= ac
b=remainder
a=is less than c
b=remainder
c= greater than a
Answer:
Explanation:
import java.util.Scanner;
class Main{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
long a=sc.nextLong(); //input
long b=sc.nextLong(); //input
long c=sc.nextLong(); //input
long ans=-1;
//if b(required remainder ) is greater than a(dividend) then no answer
if(b>=a)
ans=-1;
else{
ans=(c/a)*a+b;
if(ans>c)
{
ans=(c/a-1)*a+b;
if(ans<0)
ans=-1;
}
}
System.out.println(ans);
}
}
}