#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  long long int n, k, a, b;
  while (~scanf("%lld %lld %lld %lld", &n, &k, &a, &b)) {
    long long int ans = 0;
    if (k == 1)
      ans = a * (n - 1);
    else {
      while (n > 1) {
        if (n < k) {
          ans += a * (n - 1);
          break;
        }
        if (n % k) {
          ans += a * (n - n / k * k);
          n = n / k * k;
        }
        if ((n - n / k) * a > b) {
          ans += b;
          n = n / k;
        } else {
          ans += (n - 1) * a;
          break;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
