Moduloinator
Practice
3 (2 votes)
Maths
Problem
38% Success 1156 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Perry and Doof have \(a\) and \(b\) chocolates respectively (where \(a > b\)). Doof has a special device Moduloinator in which he can set the value of  \(M\) between \(1\)and \(a\). And when he pushes the button, the number of chocolates that Perry has becomes \(a \,{mod}\, M\).Specifically new value of  \(a\) becomes \(a \,{mod}\, M\).

 

He can use the device as many times as he wants, and also he can change the value of \(M\) every time.

Is Doof’s device useful enough to exactly equalize the chocolates of him and Perry?

 

Input Format

  • First-line contains integer \(T\), the number of test cases.

  • Next \(T\) lines contain two integers \(a\) and \(b\).

 

Output Format

  • For every test case output, the minimum number of times Doof needs to use the device to equalize the chocolates or print  \(-1\) if not possible.

 

Constraints

  • \(1 \leq T \leq 10\)

  • \(1 \leq b < a \leq 10^6\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
Tags:
ImplementationEasyMath
Points:20
2 votes
Tags:
MathObservationBasic MathC++
Points:20
125 votes
Tags:
Ad-HocOpenApprovedSimple-mathEasyMathamatics