#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const double eps = 0.0000000001;
const double pi = acos(-1);
const long long mod = 1e9 + 7;
const int hash_mod = 19260817;
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
inline double dbread() {
  double X = 0, Y = 1.0;
  int w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = X * 10 + (ch ^ 48), ch = getchar();
  ch = getchar();
  while (isdigit(ch)) X += (Y /= 10) * (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long q_pow(long long base, long long p) {
  long long result = 1;
  while (p > 0) {
    if (p & 1) {
      result = result * base % 1000;
    }
    p >>= 1;
    base = (base * base) % 1000;
  }
  return result;
}
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
const int N = 1e4 + 1;
int fri[N];
void init() {
  for (int i = 1; i <= N; i++) fri[i] = i;
}
int find(int a) {
  int tem1 = a, tem2;
  while (a != fri[a]) a = fri[a];
  while (tem1 != a) {
    tem2 = fri[tem1];
    fri[tem1] = a;
    tem1 = tem2;
  }
  return a;
}
void Union(int a, int b) {
  int fri_a = find(a);
  int fri_b = find(b);
  if (fri_a != fri_b) fri[fri_a] = fri_b;
}
char s[maxn];
int a[maxn];
long long n, k, A, B;
long long ans;
int main() {
  n = read();
  k = read();
  A = read();
  B = read();
  if (k == 1) {
    ans = A * (n - 1);
    printf("%lld\n", ans);
    return 0;
  }
  while (n != 1) {
    if (n % k == 0) {
      if ((n - n / k) * A < B)
        ans += (n - n / k) * A;
      else
        ans += B;
      n /= k;
    } else if (n > k) {
      int t = n % k;
      ans += t * A;
      n -= t;
    } else {
      ans += (n - 1) * A;
      break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
