Min Chain (ext_gcd)

                                      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的,因为那样就不能求最大公约数了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值