给两个数字a,b,每次操作可以把a+1a+1,或把a∗k
问至少多少次操作可以使得a=b.
1<=a,b<=10^18,0 <= k <= 10^18#include <bits/stdc++.h> using namespace std; long long a, b, k,ans; int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> a >> b >> k; for (;k > 1 && a <= b / k; ans += b%k + 1, b /= k); cout << ans + b - a << endl; return 0; }