Suggestions needed to solve this question

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 reminder b when divided by a

constraints
1<=t<=1000
1<=a,b,c<=10^18

sample input

2
3 2 9
1 2 4

sample output

8
-1

Please suggest any approach to solve this question.
it was from todays hackwithinfy slot 2:30 to 5:30 and this test is cancelled too.

Provide problem link to prove it is not from an ongoing contest.

2 Likes

Your problem is not clear. Why the second output is -1? does the problem says that you should print -1 if there is no number like this? Please give the problem link!

You write at the right moment, I was about to reply my answer. :joy: :joy:

Beacuse answer is not possible in that case

1 Like

I thought that too. thanks. but as @everule1 said you should provide the problem link.

it was from todays hackwithinfy slot 2:30 to 5: 40 now it is ended.

First Observation is that if (b>=a), the answer will be -1. because a remainder can’t be greater than or equal to the divisor. Suppose our answer is x. Now, the qoutient for x can be a maximum of (c-b)/a. Now, just multiply the qoutient with a and then add the remainder to get the desired solution. Therefore, ans= a*((c-b)//a)+b