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