#include <bits/stdc++.h>
using namespace std;
const long long N = 20005;
const long long M = 200001;
const long long INF = 0x3f3f3f;
const double inf = 2e9 + 7;
const double Pi = acos(-1);
const long long MOD = 1e9 + 7;
const double eps = 1e-7;
long long n, m;
long long k, a, b;
int main() {
  while (~scanf("%I64d%I64d%I64d%I64d", &n, &k, &a, &b)) {
    long long ans = -1;
    if (k == 1)
      ans = (n - 1) * a;
    else {
      ans = 0;
      long long x = n;
      while (x != 1) {
        if (x % k == 0) {
          long long t = x / k;
          if ((x - t) * a <= b)
            ans += (x - t) * a;
          else
            ans += b;
          x = t;
        } else {
          if (x > k) {
            ans += a * (x % k);
            x -= (x % k);
          } else {
            ans += a * (x - 1);
            x = 1;
          }
        }
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
