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