开始计概A下半学期。
This commit is contained in:
1 parent
0cfdc8499c
commit
38e97654e1
31 files changed
+2144
-110
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#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;
|
||||
}
|
||||
Reference in new issue
Block a user