#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  long long cnt = 0;
  long long x = n;
  if (k == 1) {
    cout << a * (x - 1) << '\n';
    return 0;
  }
  while (x > 1) {
    long long delta = x - ((x / k) * k);
    if (x < k) {
      cnt += a * (x - 1);
      break;
    }
    x -= delta;
    cnt += a * delta;
    if (x == 1) break;
    while (x > 1 && x % k == 0) {
      if (a * (x - x / k) > b) {
        cnt += b;
      } else {
        cnt += a * (x - x / k);
      }
      x = x / k;
    }
  }
  cout << cnt << "\n";
  return 0;
}
