Problem C
Min Chain
Pr oblem Des cr iption
Raven likes games of numbers. Today he meets two numbers and thinks whether
he could get a result of 1 by doing at least one operation (addition or subtraction).
However, he is tired of calculation; he also wants to know the minimum steps of
operation that he could get 1.
Input Details
The first line of the input contains an integer T, which indicates the number of test
cases.
In the following T rows, there are two positive integers a, b ( 0<=a, b<=10^9) in
each row.
Output Details
For each case, output the least number of steps.
If you cannot get 1, just output -1.
Sample I nput
3
32
16 9
68
Sample Output
1
10
-1
这是去年四省赛的一题,有人说用扩展gcd做,就看了看。写完错了N回,按数据改,最后对了,但程序对不对也不知道。
特殊情况就是两个数中有0和1的,因为那样就不能求最大公约数了。