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