#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 7;
const double eps = 0.00000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <typename T>
inline T powMM(T a, T b) {
  T ret = 1;
  for (; b; b >>= 1ll, a = 1ll * a * a % M)
    if (b & 1) ret = 1ll * ret * a % M;
  return ret;
}
int n, m;
int i, j, k;
int ans;
int main() {
  long long n, k, A, B, ans;
  scanf("%I64d%I64d%I64d%I64d", &n, &k, &A, &B);
  if (k == 1) {
    printf("%I64d\n", (n - 1) * A);
  } else {
    ans = 0;
    while (n != 1) {
      if (n % k != 0) {
        long long nxtN = max(1ll, n / k * k);
        ans += A * (n - nxtN);
        n = nxtN;
      } else {
        ans += min(B, A * (n - n / k));
        n = n / k;
      }
    }
    printf("%I64d\n", ans);
  }
}
