Decreasing Srrnmieeda October Cook off challenge Solution | Easy Explain Decreasing Srrmieeda-
Problem Statement-
You are given two integers and . Find the smallest non-negative integer such that
Here, is the modulo operator, so is the remainder of after division by . For example, .
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains two space-separated integers and .
Output
For each test case, print a single line containing one integer ― the smallest possible , or if no solution exists.
It is guaranteed that when a solution exists, the smallest solution does not exceed .
Constraints
Example Input
2
4 6
1 2
Example Output
6
-1
Explanation
Example case 1: satisfies the given condition, since . Notice that also satisfies the condition, but it is larger.
Example case 2: It is impossible to find a valid solution because for any non-negative integer , we have .
Problem Link-https://www.codechef.com/COOK123B/problems/DECREM
Join Telegram For Competetive Programming Guide and Update-https://t.me/competitiveProgrammingDiscussion
Decreasing Srrnmieeda Solution -
1-So for satisfying first relationship N should be between >=R otherwise condition one cannot be satisfied.
Comments
Post a Comment