#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b, x, ans;
int main() {
  ios_base ::sync_with_stdio(false);
  cin >> n >> k >> a >> b;
  if (k == 1) {
    cout << (n - 1) * a;
    return 0;
  }
  x = n;
  while (x != 1) {
    if (x < k || (x - x / k) * a < b) {
      ans += a * (x - 1);
      break;
    }
    long long t = x % k;
    ans += t * a;
    x -= t;
    while (x % k == 0 && (x - x / k) * a >= b) {
      x /= k;
      ans += b;
    }
  }
  cout << ans;
}
