#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, a, b, ans = 0;
  cin >> n >> k >> a >> b;
  if (k == 1)
    cout << (n - 1) * a;
  else {
    while (n != 1) {
      long long u = n / k * k;
      if (u == 0)
        ans += (n - 1) * a, n = 1;
      else
        ans += (n - u) * a + min((u - u / k) * a, b), n = u / k;
    }
    cout << ans;
  }
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  while (t--) solve();
  return 0;
}
