update
This commit is contained in:
parent
267483c098
commit
76e6a85b44
@ -1,11 +1,12 @@
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
using ull = unsigned long long;
|
||||
|
||||
auto &is = std::cin;
|
||||
auto &os = std::cout;
|
||||
|
||||
ull n, a, b;
|
||||
ull n, a, b, depth;
|
||||
|
||||
/*
|
||||
cal(a,b)
|
||||
@ -16,7 +17,28 @@ cal(a,b)
|
||||
5)a<b/2 && b is odd return cal(a,b/2)+1;
|
||||
6)a<b/2 && b is even return cal(a,b-1)+1;
|
||||
*/
|
||||
ull cal(ull a,ull b){
|
||||
if(a==b){
|
||||
return 0;
|
||||
}else if(a>b){
|
||||
if(a&1)return cal(a+1,b)+1;
|
||||
else return cal(a/2,b)+1;
|
||||
}else if(a>b/2){
|
||||
if(a*2-b<b-a){
|
||||
if(b&1)return cal(a,b-1)+1;
|
||||
else return cal(a,b/2)+1;
|
||||
}else return b-a;
|
||||
}else if(a<=b/2){
|
||||
if(b&1)return cal(a,b+1)+1;
|
||||
else return cal(a,b/2)+1;
|
||||
}
|
||||
throw std::runtime_error("cannot calculate");
|
||||
}
|
||||
|
||||
int main(){
|
||||
|
||||
is>>n;
|
||||
for(ull i {0};i<n;i++){
|
||||
is>>a>>b;
|
||||
os<<cal(a,b)<<'\n';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user