#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main() {
  i64 n, k, a, b;
  scanf("%lld %lld %lld %lld", &n, &k, &a, &b);
  i64 cost = 0;
  if (k == 1) {
    cost = a * (n - 1);
  } else {
    while (n > 1) {
      if (n % k == 0) {
        i64 next = n / k;
        cost += min((n - next) * a, b);
        n = next;
      } else if (n > k) {
        cost += a * (n % k);
        n -= n % k;
      } else {
        cost += a * (n - 1);
        n = 1;
      }
    }
  }
  printf("%lld", cost);
  return 0;
}
