#include <bits/stdc++.h>
using namespace std;
int n, k;
long long a, b;
int main() {
  scanf("%d%d%lld%lld", &n, &k, &a, &b);
  if (k == 1) {
    printf("%lld", a * (n - 1));
    return 0;
  }
  int cur = n;
  long long how = 0;
  while (1) {
    if (cur == 1) break;
    if (cur % k != 0) {
      how += a * (cur % k);
      cur -= cur % k;
      if (cur == 0) {
        cur++;
        how -= a;
      }
    } else {
      if ((cur - cur / k) * a >= b) {
        cur = cur / k;
        how += b;
      } else {
        how += a * (cur - 1);
        cur = 1;
      }
    }
  }
  printf("%lld", how);
}
