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