func_code_string: #include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k, a, b;     cin >> n >> k >> a >> b;     if (k == 1) {       cout << (n - 1) * a << endl;       return 0;     }     long long ans = 0;     while (n != 1) {       if (n >= k) {         long long md = n % k;         ans += md * a;         n -= md;         long long prev = n;         long long curr = n / k;         ans += min(a * (prev - curr), b);         n /= k;       } else if (n < k) {         ans += (n - 1) * a;         break;       }     }     cout << ans << endl;     return 0;   }   