#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n, k, a, b, c = 0;
    cin >> n >> k >> a >> b;
    if (k == 1) {
      cout << (n - 1) * a << endl;
      return 0;
    }
    while (n >= k) {
      if (!(n % k)) {
        c += min(b, (n - n / k) * a);
        n /= k;
      } else {
        c += (n % k) * a;
        n -= (n % k);
      }
    }
    c += (n - 1) * a;
    cout << c << endl;
  }
  return 0;
}
