#include <bits/stdc++.h>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 19260817;
long long s;
int main() {
  long long n, m, a, b;
  scanf("%I64d%I64d%I64d%I64d", &n, &m, &a, &b);
  if (m == 1) {
    s = (n - 1) * a;
    cout << s;
    return 0;
  }
  long long t = n;
  while (t != 1) {
    if (t < m) {
      s += (t - 1) * a;
      t = 1;
      break;
    }
    if (t % m == 0) {
      s += min(b, (t - t / m) * a);
      t /= m;
    }
    if (t < m) {
      s += (t - 1) * a;
      t = 1;
      break;
    }
    if (t % m != 0) {
      s += (t - (t / m) * m) * a;
      t = t / m * m;
    }
    if (t < m) {
      s += (t - 1) * a;
      t = 1;
      break;
    }
  }
  printf("%I64d", s);
  return 0;
}
