21 lines
527 B
C++
21 lines
527 B
C++
#include <cmath>
|
|
#include <iostream>
|
|
|
|
long long calc_min_ops(long long a, long long b) {
|
|
if (a > b) { return a - b; }
|
|
long long div = b / a;
|
|
auto multiply_times = static_cast<long long>(std::log2(div));
|
|
a = a * std::pow(2, multiply_times);
|
|
return std::min(multiply_times + b - a, multiply_times + 1 + (2 * a - b));
|
|
}
|
|
|
|
int main() {
|
|
std::ios::sync_with_stdio(false);
|
|
std::cin.tie(nullptr);
|
|
long long a, b;
|
|
std::cin >> a >> b;
|
|
std::cout << calc_min_ops(a, b) << std::endl;
|
|
|
|
return 0;
|
|
}
|