update
This commit is contained in:
parent
f3f3fbc327
commit
d1288853ee
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using ull = unsigned long long;
|
using ull = unsigned long long;
|
||||||
|
|
||||||
@ -24,12 +25,11 @@ ull cal(ull a,ull b){
|
|||||||
if(a&1)return cal(a+1,b)+1;
|
if(a&1)return cal(a+1,b)+1;
|
||||||
else return cal(a/2,b)+1;
|
else return cal(a/2,b)+1;
|
||||||
}else if(a>b/2){
|
}else if(a>b/2){
|
||||||
if(a*2-b<b-a){
|
const auto ans = b-a;
|
||||||
if(b&1)return cal(a,b-1)+1;
|
if(b&1)return std::min(ans,cal(a,b-1)+1);
|
||||||
else return cal(a,b/2)+1;
|
else return std::min(ans,cal(a,b/2)+1);
|
||||||
}else return b-a;
|
|
||||||
}else if(a<=b/2){
|
}else if(a<=b/2){
|
||||||
if(b&1)return cal(a,b+1)+1;
|
if(b&1)return cal(a,b-1)+1;
|
||||||
else return cal(a,b/2)+1;
|
else return cal(a,b/2)+1;
|
||||||
}
|
}
|
||||||
throw std::runtime_error("cannot calculate");
|
throw std::runtime_error("cannot calculate");
|
||||||
|
Loading…
Reference in New Issue
Block a user