#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
inline void gn(long long &first) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, first = 0) : (first = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') first = first * 10 + c - '0';
  first *= sg;
}
inline void gn(int &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(unsigned long long &first) {
  long long t;
  gn(t);
  first = t;
}
inline void gn(double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
inline void gn(long double &first) {
  double t;
  scanf("%lf", &t);
  first = t;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int main() {
  long long k, b, n, t, m;
  scanf("%I64d%I64d%I64d%I64d", &k, &b, &n, &t);
  if (k == 1) {
    m = n - (t - 1) / b;
    if (m < 0) m = 0;
    cout << m << endl;
    return 0;
  }
  double u = 1.0 * (t - t * k - b) / (1 - k - b);
  double v = log(u) / log(1.0 * k);
  m = n - floor(v);
  if (m < 0) m = 0;
  printf("%I64d\n", m);
  return 0;
}
