#include <bits/stdc++.h>
const int maxn = 2000000;
int k, b, n, t;
int result;
int a[maxn + 1], bb[maxn + 1], atop, bbtop;
bool xiaodeng() {
  int i;
  if (bbtop < atop) return false;
  if (bbtop > atop) return true;
  for (i = atop; i >= 1; --i) {
    if (a[i] > bb[i]) return false;
    if (bb[i] > a[i]) return true;
  }
  return true;
}
void calc(int a[], int &top, int k, int b, int n, int x) {
  int i, j, s;
  top = n;
  for (i = 1; i <= n - 1; ++i) a[i] = b;
  a[n] = x;
  s = 0;
  for (i = 1;; ++i) {
    if (i <= top) s += a[i];
    if ((i > top) && (s == 0)) break;
    if (i > top) ++top;
    a[i] = s % k;
    s /= k;
  }
}
int main() {
  scanf("%d%d%d%d", &k, &b, &n, &t);
  ++n;
  if (k == 1) {
    long long tmp = n - 1;
    tmp = tmp * b + 1;
    tmp = tmp - t + b;
    if (tmp < 0)
      result = 1;
    else {
      if (tmp % b == 0)
        result = tmp / b;
      else
        result = tmp / b + 1;
    }
  } else {
    calc(a, atop, k, b, n, 1);
    int start = 1, stop = n, mid;
    while (start <= stop) {
      mid = (start + stop) / 2;
      calc(bb, bbtop, k, b, mid, t);
      if (xiaodeng()) {
        stop = mid - 1;
        result = mid;
      } else
        start = mid + 1;
    }
  }
  printf("%d\n", result - 1);
  return 0;
}
