#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b;
  cin >> n >> k >> a >> b;
  long long x = n, y;
  long long t = 0;
  if (k == 1) {
    cout << (n - 1) * a << endl;
    return 0;
  }
  while (x > 1) {
    y = x / k;
    if (y < 1) break;
    t += min(b + (x - y * k) * a, (x - y) * a);
    x = y;
  }
  t += (x - 1) * a;
  cout << t << endl;
}
