#include <bits/stdc++.h>
using namespace std;
struct fastIO {
  fastIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
};
const int MAXN = 1e6;
long long n, x, a, b, k, ans, y;
int main() {
  fastIO();
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << a * (n - 1);
    return 0;
  }
  while (n != 1) {
    if (n % k != 0) {
      ans += a * (n % k);
      n -= n % k;
    }
    x = n - (n / k);
    if (x * a < b) {
      ans += a * (n - 1);
      n = 1;
    } else {
      n /= k;
      ans += b;
    }
  }
  cout << ans;
  return 0;
}
