#include <bits/stdc++.h>
#pragma gcc optimize(o3)
using namespace std;
const long long N = 1e6 + 1000;
long long k, b, n, t;
long long arr[N], xx[N];
bool chk(long long mid) {
  memset(xx, 0, sizeof xx);
  xx[mid] = t - b;
  for (int i = 0; i <= mid; i++) {
    xx[i] += b;
    xx[i + 1] += (xx[i] - (xx[i] % k)) / k;
    xx[i] %= k;
  }
  for (int i = mid + 1; i < N - 1; i++) {
    xx[i + 1] += (xx[i] - (xx[i] % k)) / k;
    xx[i] %= k;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (arr[i] > xx[i]) return 0;
    if (arr[i] < xx[i]) return 1;
  }
  return 1;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &k, &b, &n, &t);
  arr[n] = 1 - b;
  for (int i = 0; i <= n; i++) {
    arr[i] += b;
    arr[i + 1] += (arr[i] - (arr[i] % k)) / k;
    arr[i] %= k;
  }
  for (int i = n + 1; i < N - 1; i++) {
    arr[i + 1] += (arr[i] - (arr[i] % k)) / k;
    arr[i] %= k;
  }
  long long s = 0, e = n, mid, mx = n;
  while (s <= e) {
    mid = (s + e) >> 1;
    if (chk(mid)) {
      mx = mid;
      e = mid - 1;
    } else
      s = mid + 1;
  }
  printf("%I64d", mx);
  return 0;
}
