#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int ZEROS = (int)(1E+2 * 5 + 100);
const int INF = (int)1E+9;
long long n, k, a, b, ans;
void solve() {
  if (k == 1) {
    cout << (n - 1) * a;
    return;
  }
  while (n > 1) {
    if (n % k == 0) {
      ans += min(b, (n - n / k) * a);
      n /= k;
    } else if (n - 1 < k) {
      ans += (n - 1) * a;
      n = 1;
    } else {
      ans += (n - (n / k) * k) * a;
      n = (n / k) * k;
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> a >> b;
  solve();
}
