#include <bits/stdc++.h>
long long int n, k, a, b;
long long int miin(long long int a, long long int b) { return a < b ? a : b; }
int main() {
  scanf("%lld%lld%lld%lld", &n, &k, &a, &b);
  long long int sum = 0;
  if (k == 1) {
    sum += a * (n - 1);
    printf("%lld\n", sum);
    return 0;
  }
  while (n != 1) {
    if (n < k) {
      sum += a * (n - 1);
      break;
    }
    if (n % k != 0) {
      sum += a * (n - n / k * k);
      n = n / k * k;
    }
    sum += miin(b, a * (n - n / k));
    n = n / k;
  }
  printf("%lld\n", sum);
  return 0;
}
