#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k, a, f, b, i, c, t, l;
  cin >> n >> k >> a >> b;
  t = n;
  c = 0;
  if (k == 1) {
    cout << a * (n - 1);
    exit(0);
  }
  while (n > 1) {
    if (n % k == 0) {
      c += min((n - n / k) * a, b);
      n = n / k;
    } else
      c += a * (n % k), n -= (n % k);
  }
  if (n == 0) c -= a;
  cout << c;
  return 0;
}
