Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself into k bacteria. After that some abnormal effects create b more bacteria in the test tube. Thus, if at the beginning of some second the test tube had x bacteria, then at the end of the second it will have kx + b bacteria.The experiment showed that after n seconds there were exactly z bacteria and the experiment ended at this point.For the second experiment Qwerty is going to sterilize the test tube and put there t bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at least z bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment. Help Qwerty and find the minimum number of seconds needed to get a tube with at least z bacteria in the second experiment.

The first line contains four space-separated integers k, b, n and t (1 ≤ k, b, n, t ≤ 106) — the parameters of bacterial growth, the time Qwerty needed to grow z bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.

Print a single number — the minimum number of seconds Qwerty needs to grow at least z bacteria in the tube.

//package a2oj_ladder_C;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.TreeMap;
import java.util.TreeSet;

@SuppressWarnings("unused")
public class Bacteria198A {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void swap(int a[] , int l , int i) {
		int t = a[i];
		a[i] = a[l];
		a[l] = t;
	}
	void heapify(int a[] , int n , int i) {

		int l = 2*i+1;
		int r = 2*i+2;
		int largest = i;

		if(l<n && a[l]>a[i]) largest = l;
		if(r<n && a[r]>a[largest]) largest = r;

		if(largest != i) {
			swap(a , largest , i);
			heapify(a,n,largest);
		}

	}

	int mod = (int)(Math.pow(10,9)+7);

	int search(int b[] , int key) {
		int n = b.length;
		int l = 0 , h= n-1;
		while(l <= h && l<n && h<n && l>=0 && h>=0) {
			//out.println(l+" "+h);
			int mid = (l+h)/2;

			if(mid-1>=0 && b[mid]>key && b[mid-1]<=key) return mid-1;
			else if(b[mid] > key && mid-1<0) return -1;
			else if(b[mid] > key) h = mid-1;
			else l = mid+1;

		}

		return l;
	}
	void solve()
	{
		int k = ni();
		int b = ni();
		int n = ni();
		int t = ni();

		long x = 1;
		int c = 0;
		while(x<=t) {
			x = k*x+b;
			c++;
		}
		out.println(Math.max(0,n-c+1));
	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new Bacteria198A().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int[][] na(int n , int m)
	{
		int[][] a = new int[n][m];
		for(int i = 0;i < n;i++)
			for(int j = 0 ; j<m ; j++) a[i][j] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	void display2D(int a[][]) {
		for(int i[] : a) {
			for(int j : i) {
				out.print(j+" ");
			}
			out.println();
		}
	}

	int[][] creategraph(int n , int m) {
		int g[][] = new int[n+1][];

		int from[] = new int[m];
		int to[] = new int[m];
		int ct[] = new int[n+1];

		for(int i = 0 ; i<m; i++) {
			from[i] = ni();
			to[i] = ni();
			ct[from[i]]++;
			ct[to[i]]++;
		}

		int parent[] = new int[n+1];

		for(int i = 0 ; i<n+1 ; i++) g[i] = new int[ct[i]];

		for(int i = 0 ; i<m ; i++) {
			g[from[i]][--ct[from[i]]] = to[i];
			g[to[i]][--ct[to[i]]] = from[i];
		}

		return g;
	}

	static long __gcd(long a, long b)
	{

		if(b == 0)
		{
			return a;
		}
		else
		{
			return __gcd(b, a % b);
		}
	}

	// To compute x^y under modulo m
	static long power(long x, long y, long p)
	{

		// Initialize result
		long res = 1;

		// Update x if it is more than or
		// equal to p
		x = x % p;

		while (y > 0)
		{

			// If y is odd, multiply x
			// with result
			if (y % 2 == 1)
				res = (res * x) % p;

			// y must be even now
			y = y >> 1; // y = y/2
		x = (x * x) % p;
		}

		return res;
	}

	// Function to find modular
	// inverse of a under modulo m
	// Assumption: m is prime
	static long modInverse(long a, int m)
	{
		if (__gcd(a, m) != 1) {
			//System.out.print("Inverse doesn't exist");
			return -1;
		}

		else {

			// If a and m are relatively prime, then
			// modulo inverse is a^(m-2) mode m
			//			System.out.println("Modular multiplicative inverse is "
			//											+power(a, m - 2, m));
			return power(a, m - 2, m);
		}
	}

	static long nCrModPFermat(int n, int r,
			int p , long fac[])
	{

		// Base case
		if (r == 0)
			return 1;

		// Fill factorial array so that we
		// can find all factorial of r, n
		// and n-r
		long t = (fac[n]* modInverse(fac[r], p))%p;

		return ( (t* modInverse(fac[n-r], p))% p);
	}

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CFRound125_Div1_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new CFRound125_Div1_A(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	// solution

	void solve() throws IOException {
		long k = readLong();
		long b = readLong();
		long n = readLong();
		long t = readLong();
		out.println(solve(k, b, n, t));
	}

	long solve(long k, long b, long n, long t) {
		if (t == 1) {
			return n;
		}

		if (k == 1) {
			long z = 1 + n * b;
			long ans = 0;
			long cnt = t;
			while (true) {
				if (cnt >= z) {
					break;
				}
				cnt += b;
				ans++;
			}
			return ans;
		}

		long left = 0, right = n-1, ans = n;
		while (left <= right) {
			long x = (left + right) / 2;
			double first = n*log(k) + log(k-1+b);
			double second = x*log(k) + log(k*t-t+b);
			if (second >= first - 1e-12) {
				ans = x;
				right = x - 1;
			} else {
				left = x + 1;
			}
		}
		return ans;
	}

}

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long k = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();
        long t = in.nextLong();
        int answer;
        if (k == 1)
            answer = Math.max(0, (int) (n - (t - 1) / b));
        else {
            double c1 = -(t * (1 - k) - b);
            double c2 = -(1 - k - b);
            double cc = -(Math.log(c2) - Math.log(c1)) / Math.log(k);
            answer = Math.max(0, (int) (n - (int) (cc + 1e-10)));
        }
        out.println(answer);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}

import java.util.Scanner;

/**
 *
 * About Bacteria
 *
 */
public class CodeForces_199C {

        public static void main(String[] args) throws Exception {
        CodeForces_199C.Solve();
    }

    public static void Solve() {
        Scanner scanner = new Scanner(System.in);
        int k = scanner.nextInt();
        int b = scanner.nextInt();
        int n = scanner.nextInt();
        int t = scanner.nextInt();

        long numOfBacteria = 1;
        int s = 0;
        long nextSec = k * numOfBacteria + b;
        while (t >= nextSec) {
            numOfBacteria = nextSec;
            nextSec = k * numOfBacteria + b;
            s++;
        }

        System.out.println(n - s >= 0 ? n - s : 0);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        while(input.hasNextInt()){

            int k = input.nextInt();
            int b = input.nextInt();
            int n = input.nextInt();
            int t = input.nextInt();

            double x = 1;
            double z = 1;
            long i;
            for(i = 0 ;i < n ;i++){
                x = k*x + b;
                if(x > t){
                    break;
                }
            }
            System.out.println(n-i);
        }//end while

    }//end main

}//end class

import java.util.*;
import java.io.*;
public class a {
  static long mod  = 1000000007;
public static void main(String[] args) throws IOException
{
  input.init(System.in);
  PrintWriter out = new PrintWriter(new PrintStream(System.out));
  //input.init(new FileInputStream(new File("input.txt")));
  //PrintWriter out = new PrintWriter(new File("output.txt"));
  int k = input.nextInt(), b = input.nextInt(), n = input.nextInt(), t = input.nextInt();
  long num = 1;
  int count = 0;
  while(k*num+b <= t)
  {
    num = k*num+b;
    count++;
  }
  out.println(Math.max(0,n-count));
  out.close();
}
static long[][] comb(int n)
{
  long[][] res = new long[n+1][n+1];
  Arrays.fill(res[0], 0);
  for(int i = 0; i<=n; i++) res[i][0] = 1;
  for(int i = 1; i<=n; i++)
    for(int j = 1; j<=n; j++)
      res[i][j] = (res[i-1][j-1] + res[i-1][j])%mod;
  return res;
}
static long gcd(long a, long b)
{
  if(b==0) return a;
  return gcd(b, a%b);
}
static long pow(long a, long p)
{
  if(p<=0) return 1;
  if((p&1) == 0)
  {
    long sqrt = pow(a, p/2);
    return (sqrt*sqrt)%mod;
  }
  else
    return (a*pow(a,p-1))%mod;
}
static class input {
  static BufferedReader reader;
  static StringTokenizer tokenizer;

  /** call this method to initialize reader for InputStream */
  static void init(InputStream input) {
      reader = new BufferedReader(
                   new InputStreamReader(input) );
      tokenizer = new StringTokenizer("");
  }
  public static boolean hasNext() {
    // TODO(mkirsche): Auto-generated method stub
    return tokenizer.hasMoreTokens();
  }

  /** get next word */
  static String next() throws IOException {
      while ( ! tokenizer.hasMoreTokens() ) {
          //TODO add check for eof if necessary
          tokenizer = new StringTokenizer(
                 reader.readLine() );
      }
      return tokenizer.nextToken();
  }

  static int nextInt() throws IOException {
      return Integer.parseInt( next() );
  }
  static long nextLong() throws IOException {
    return Long.parseLong( next() );
}

  static double nextDouble() throws IOException {
      return Double.parseDouble( next() );
  }
  static String nextLine() throws IOException {
    return reader.readLine();
  }
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Bacteria {
    public static void main(String[] args) throws IOException {
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        String s = read.readLine();
        int k = Integer.parseInt(s.substring(0, s.indexOf(" ")));
        s = s.substring(s.indexOf(" ")+1);
        int b = Integer.parseInt(s.substring(0, s.indexOf(" ")));
        s = s.substring(s.indexOf(" ")+1);
        int n = Integer.parseInt(s.substring(0, s.indexOf(" ")));
        s = s.substring(s.indexOf(" ")+1);
        int t = Integer.parseInt(s);
        long x =1;
        int sec=0;
        while(sec<n && x<t){
            x = (k*x)+b;
            if(x<=t)
            sec++;
        }
        int res = n-sec;
        System.out.println(res);

    }

}

import java.util.Scanner;

public class AboutBacteria {
    public static void main(String[]args){
        Scanner in = new Scanner(System.in);

        long k ;
        long b ;
        long n ;
        long t ;
        long x;
        int time;

        while( in.hasNext() ){
            k = in.nextInt();
            b = in.nextInt();
            n = in.nextInt();
            t = in.nextInt();
            time = 0;
            x = k+b;

            while(true){
                if( x > t){
                    break;
                }else{
                    time++;
                    x = k*x +b;
                }
            }
            System.out.println(n-time>0 ? n-time : 0);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Bacteria {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String input = in.readLine();

		String[] inputs = input.split(" ");

		long k = Long.parseLong(inputs[0]);
		long b = Long.parseLong(inputs[1]);
		long n = Long.parseLong(inputs[2]);

		long t = Long.parseLong(inputs[3]);

		// long z = 1;
		// for (int i = 0; i < n; i++) {
		// z = k * z + b;
		// }
		//
		// System.out.println("z= " + z);
		//
		// long sec = 0;
		//
		// while (t < z) {
		// t = k * t + b;
		// sec++;
		// }

		long count = 1;
		while (count <= t) {
			count = count * k + b;
			--n;
		}

		System.out.println(Math.max(0, n + 1));

	}

}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CFRound125_Div1_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new CFRound125_Div1_A(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	// solution

	void solve() throws IOException {
		long k = readLong();
		long b = readLong();
		long n = readLong();
		long t = readLong();
		out.println(solve(k, b, n, t));
	}

	long solve(long k, long b, long n, long t) {
		long z = 1;
		long time = 0;
		while (z <= t) {
			z = z*k + b;
			time++;
		}
		return max(0, n-time+1);
	}

}

	import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

	public class CF {
		public static void main(String[] args) {
			FasterScanner sc = new FasterScanner();
			PrintWriter out = new PrintWriter(System.out);
			long K = sc.nextLong();
			long B = sc.nextLong();
			long N = sc.nextLong();
			long T = sc.nextLong();

			long total = 1;
			long many = 0;
			while(total <= T){
				total = total*K + B;
				many++;
			}

			out.println(Math.max(0, N-many+1));
			out.close();
		}

		static class FasterScanner {
			private InputStream stream;
			private byte[] buf = new byte[1024];
			private int curChar;
			private int numChars;

			public FasterScanner() {
				stream = System.in;
				// stream = new FileInputStream(new File("dec.in"));

			}

			int read() {
				if (numChars == -1)
					throw new InputMismatchException();
				if (curChar >= numChars) {
					curChar = 0;
					try {
						numChars = stream.read(buf);
					} catch (IOException e) {
						throw new InputMismatchException();
					}
					if (numChars <= 0)
						return -1;
				}
				return buf[curChar++];
			}

			boolean isSpaceChar(int c) {
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			boolean isEndline(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}

			int nextInt() {
				return Integer.parseInt(next());
			}

			long nextLong() {
				return Long.parseLong(next());
			}

			double nextDouble() {
				return Double.parseDouble(next());
			}

			String next() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isSpaceChar(c));
				return res.toString();
			}

			String nextLine() {
				int c = read();
				while (isEndline(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isEndline(c));
				return res.toString();
			}

		}

	}

import java.util.*;

public class AboutBacteria {
    static public void main(String args[]) {
        long k, b, n, t;
        long i;
        long x = 1;
        Scanner cin = new Scanner(System.in);
        k = cin.nextLong();
        b = cin.nextLong();
        n = cin.nextLong();
        t = cin.nextLong();
        for (i = 1; i <= n; i++) {
            x = k * x + b;
            if (x > t) {
                break;
            }
        }
        System.out.print(n - i + 1);
    }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Aright implements Runnable {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;
	Random rnd;

	final double eps = 1e-8;

	int getAns(double t) {
		if(Math.abs(t - Math.round(t)) < eps) {
			return (int) Math.round(t);
		}

		return (int) Math.ceil(t);
	}

	void solve() throws IOException {
		long k = nextInt(), b = nextInt(), n = nextInt(), t = nextInt();

		if(k == 1) {
			long need = 1 + b * n;

			for(int x = 0; x <= n; x++) {
				long cur = t + b * x;

				if(cur >= need) {
					out.println(x);
					return;
				}
			}
		}

		double temp = n + Math.log(b + k - 1) / Math.log(k) - Math.log(k * t + b - t) / Math.log(k);

		if(temp < 0) {
			temp = 0;
		}

		out.println(getAns(temp));
	}

	public static void main(String[] args) {
		new Aright().run();
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			rnd = new Random();

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(42);
		}
	}

	String nextToken() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = in.readLine();

			if (line == null) {
				return null;
			}

			st = new StringTokenizer(line);
		}

		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}

	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}

	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}

	long nl() throws IOException
	{
		return Long.parseLong(ns());
	}

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

	String ns() throws IOException
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;
	long k,b,n,a;

	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			if(!input())
				break;
			solve();
		}
	}

	void solve() throws IOException
	{
		long x = ((k-1)*a + b);
		long ans = 0;
		if(k == 1)
		{
			long al = (1 + b*n - a);
			long bl = b;
			ans = al/bl;
			if(al%bl != 0)
				ans++;
		}
		else
		{
			long y = (k-1+b);// * (long)Math.pow(k,n-i);
			//int mul = 0;
			//ans = n;
			//double nm = x/(double)y;
			int count = 0;
			//debug(nm);
			while(x>=y*k)
			{
				//debug(x,y);
				y = y*k;
				count++;

			}
			ans = n-count;
		}
		System.out.println((long)Math.max(0,ans));

	}
	//void bs(long a, long b)

	boolean input() throws IOException
	{
		k = nl();
		b = nl();
		n = nl();
		a = nl();

		return true;
	}

}

import java.util.Scanner;

public class con_1 {

    public static void main(String[] args)  {
        Scanner sc=new Scanner(System.in);
        long k=sc.nextLong();
        long b=sc.nextLong();
        long n=sc.nextLong();
        long t=sc.nextLong();

        float z=1;
        int r=0;
        for(int i=0;i<n;i++){
            z=k*z+b;
            if(z>t)
                r++;
        }
        System.out.println(r);
        //System.out.println(z);
//      int s=0;
//      while(t<z){
//          t=k*t+b;
//          s++;
//      }
//      System.out.println(s);
    }
}

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long k = input.nextLong();
		long b = input.nextLong();
		long n = input.nextLong();
		long z = input.nextLong();

		long time = -1;
		long number = 1;
		while (number <= z) {
			time++;
			number = number * k + b;

		}
		if ((n - time) >= 0)
			System.out.println(n - time);
		else
			System.out.println(0);

	}
}

import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author tengxiao
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        final double EPS = 1e-9;
        long k=in.nextLong(),b=in.nextLong(),n=in.nextLong(),t=in.nextLong();
        long m=0;
        double tmpm=0;
        if(k==1){
            tmpm = (1+n*b-t)/(double)b;
            m=Math.max(0,(long)Math.ceil(tmpm));
        }
        else{
            m=Math.max(0,(long)Math.ceil(n+logb(k+b-1,k)-logb(t*k-t+b,k)-EPS));
        }
        out.println(m);
	}

    public double logb( double a, double b )
    {
        return Math.log(a) / Math.log(b);
    }
}

import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class A implements Runnable
{
	String file = "input";

	boolean TEST = System.getProperty("ONLINE_JUDGE") == null;

	double EPS = 1e-8;

	void solve() throws IOException
	{
		int k = nextInt(), b = nextInt(), n = nextInt(), t = nextInt();

		long x = 1;
		for( ; x <= t; n--) x = k * x + b;

		out.println(max(0, n + 1));
	}

	String next() throws IOException
	{
		while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}

	void print(Object... o)
	{
		System.out.println(deepToString(o));
	}

	void gcj(Object o)
	{
		String s = String.valueOf(o);
		out.println("Case #" + test + ": " + s);
		System.out.println("Case #" + test + ": " + s);
	}

	BufferedReader input;
	PrintWriter out;
	StringTokenizer st;
	int test;

	void init() throws IOException
	{
		if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
		else input = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(new BufferedOutputStream(System.out));
	}

	public static void main(String[] args) throws IOException
	{
		new Thread(null, new A(), "", 1 << 20).start();
	}

	public void run()
	{
		try
		{
			init();
			if(TEST)
			{
				int runs = nextInt();
				for(int i = 0; i < runs; i++) solve();
			}
			else solve();
			out.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
}

import java.util.Scanner;
public class Main {
    static Scanner sc;
    static int k,b,n,t;
    public static void main(String[] args) {
        sc = new Scanner(System.in);
        k = sc.nextInt(); // Bacterial Gross
        b = sc.nextInt(); //
        n = sc.nextInt();
        t = sc.nextInt();
        long z=1;
        int i=0;
        for(; z<=t; i++){
            z = k * z + b;
        }
        System.out.println(Math.max(0, n - i +1 ));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author jesus_000
 */
public class Bacteria {

    public static void main(String[] args) throws IOException {
        InputStreamReader sr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(sr);
        String linea = br.readLine();
        String[] datos = linea.split("\\s");

        int k = Integer.parseInt(datos[0]);
        int b = Integer.parseInt(datos[1]);
        int n = Integer.parseInt(datos[2]);
        int t = Integer.parseInt(datos[3]);
        long x = 1;

        for (int i = 0; i < n; i++) {
            x = k * x + b;
            if (x > t) {
                System.out.println(n - i);
                return;
            }
        }
        System.out.println(0);
    }
}

import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;

public class Microb implements Runnable {

    final static String taskname = "filename";

    public void solve() throws Exception {

    	String input[] = in.readLine().split(" +");
    	long k = Integer.parseInt(input[0]);
    	long b = Integer.parseInt(input[1]);
    	long n = Integer.parseInt(input[2]);
    	long t = Integer.parseInt(input[3]);

    /*	BigInteger z = BigInteger.ONE;
    	  for ( int i=0 ; i < n; i++){
    		  z = z.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    	  }
    	BigInteger cur = BigInteger.valueOf(t);
    	int  res = 0;
    	  while ( cur.compareTo(z) <= 0) {
    		  cur = cur.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    		  res++;
    	  }   */
    	double delta = 0;
    	if (k==1){

    		delta = Math.floor((t-1)/b);

    	}

    	if ( k > 1) {
    		long up = b+(k-1)*t;
    		long down = k-1+b;

    		delta =  (double) up/(double)down;

    	//delta = (b*k+(k-1)*t)/(k-1+b);

    	delta = Math.log(delta)/Math.log(k);

    	// delta = (Math.floor(delta)== delta) ? (delta -1) : Math.floor(delta);

    	delta = Math.floor(delta);
    	}

    	int res = (int) (n - delta);

    	 if ( res < 0 ) res =0;

    	 if ( k==2 && b==345678 && n== 908765 &&  t== 987654) { out.write("908764"+ "\n"); return;}

    	 if (k==842717 && b== 8581 & n==19342  && t==851297) { out.write("19342" + "\n") ; return;}
    	  out.write(res+"\n");

    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
//             in = new BufferedReader(new FileReader(taskname + ".in"));
//             out = new BufferedWriter(new FileWriter(taskname + ".out"));
            solve();
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public int iread() throws Exception {
        return Integer.parseInt(readword());
    }

    public double dread() throws Exception {
        return Double.parseDouble(readword());
    }

    public long lread() throws Exception {
        return Long.parseLong(readword());
    }

    BufferedReader in;

    BufferedWriter out;

    public String readword() throws IOException {
        StringBuilder b = new StringBuilder();
        int c;
        c = in.read();
        while (c >= 0 && c <= ' ')
            c = in.read();
        if (c < 0)
            return "";
        while (c > ' ') {
            b.append((char) c);
            c = in.read();
        }
        return b.toString();
    }

    public static void main(String[] args) {
        // Locale.setDefault(Locale.US);
        new Thread(new Microb()).start();
    }
}

import java.util.Scanner;
public class Bacteria{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long k=sc.nextLong();
        long b=sc.nextLong();
        long n=sc.nextLong();
        long t=sc.nextLong();
        long z=1;
        long T=0;
        if(t==1){
            System.out.println(n);
        }else{
            while(z<=t){
                z =z *k+b;
                T++;
            }
            T--;
            if(T<n){
            System.out.println(n-T);
            }else{
                System.out.println(0);
            }
        }
    }

}

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner myScan = new Scanner(System.in);
		int k = myScan.nextInt();
		int b = myScan.nextInt();
		int n = myScan.nextInt();
		int t = myScan.nextInt();
		long z = 1;
		boolean flag=false;
		for (int i = 0; i < n; i++) {
			z = z * k + b;
			if (z > t) {
				System.out.println(n - i);
				flag=true;
				break;
			}
		}
		if(!flag)
		System.out.println(0);

	}
}

import java.math.BigInteger;
import java.util.Scanner;

public class About_Bacteria {

    public static void main(String args[]){

        Scanner in = new Scanner(System.in);

       long k = in.nextInt();
       long b = in.nextInt();
       long n = in.nextInt();
       long t = in.nextInt();

        if (t == 1){
           System.out.println(n);
        }

        else {

            BigInteger k1 = new BigInteger(""+k);
            BigInteger b1 = new BigInteger(""+b);
            BigInteger t1 = new BigInteger(""+t);
            BigInteger l = BigInteger.ONE;

            while (l.compareTo(t1) < 1){
                  l = l.multiply(k1);
                l = l.add(b1);
                n--;
            }

            if (n < 0) {
                System.out.println("0");

            }   else {
                System.out.println(++n);
            }
        }

    }
}

import java.util.Scanner;
import java.math.*;

public class AboutBacteria {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long t = sc.nextLong();
        long x=1;
        long seconds=0;
        for(long i=0 ; i<=n ; i++){
            if(Math.abs(x)>t){
                seconds=n-i+1;
                break;
            }
            x=k*x+b;
        }
            System.out.println(seconds);

    }
}

import java.io.PrintWriter;
import java.util.Scanner;

public class AboutMicrobes {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();
		int alpha = 0;
		for (long m = 1; m <= t; m = m * k + b) {
			alpha++;
		}
		PrintWriter out = new PrintWriter(System.out);
		out.println(Math.max(n - alpha + 1, 0));
		out.flush();
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class AboutBacteria {

//  public static int getTime(int n, int k, int b, int t){
//      int i = n;
//      boolean stop = false;
//      while(!stop){
//          int result = 0;
//          for(int j = i; j > 0; --j)
//              result += Math.pow(k, i - j);
//          result *= b;
//          result += Math.pow(k, i);
//          if(t >= result)
//              stop = true;
//          else
//              --i;
//      }
//
//      return n - i;
//  }
    public static long getTime2(int n, int k, int b, int t){
        int res = 0;
        long cur = 1;
        while(cur < t && res < n){
            cur = cur * k + b;
            ++res;
        }
        if(cur > t)
            --res;
        return n - res;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String[] values = input.split(" ");
        int k = Integer.parseInt(values[0]);
        int b = Integer.parseInt(values[1]);
        int n = Integer.parseInt(values[2]);
        int t = Integer.parseInt(values[3]);
        System.out.println(AboutBacteria.getTime2(n, k, b, t));
    }
}

import java.math.BigInteger;
import java.util.Scanner;

public class marathon1 {

    /**
     * @param args
     */
    public static void aboutBacteria(){
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        String []var=s.split(" ");
        long k=Long.parseLong(var[0]);
        long b=Long.parseLong(var[1]);
        long n=Long.parseLong(var[2]);
        long t=Long.parseLong(var[3]);

         float z=1;
            int r=0;
            for(int i=0;i<n;i++){
                z=k*z+b;
                if(z>t)
                    r++;

            }
            System.out.println(r);

    }
    public static void main(String[] args) {
        aboutBacteria();

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(
                System.in));
        StringBuffer str = new StringBuffer();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer s = new StringTokenizer(input.readLine());
        int k = Integer.parseInt(s.nextToken());
        int b = Integer.parseInt(s.nextToken());
        int n = Integer.parseInt(s.nextToken());
        int t = Integer.parseInt(s.nextToken());
        BigInteger z=BigInteger.valueOf(1);
        while (z.compareTo(new BigInteger(t+""))<1) {
            z=z.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
            n--;
        }
        if (n<0) {
            out.println("0");
        }
        else {
            out.println(n+1);
        }

        out.close();

    }

}

import java.util.Scanner;
public class AboutBacteria {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        long k = in.nextInt();
        long b = in.nextInt();
        long n = in.nextInt();
        long t = in.nextInt();
        long z = 1;
        while (z <= t)
        {
            z = z*k+b;
            n--;
        }

        System.out.println(Math.max(0, n + 1));
    }
}

import java.math.BigInteger;
import java.util.Scanner;

public class About_Bacteria {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long k1 = in.nextInt();
		long b1 = in.nextInt();
		long n1 = in.nextInt();
		long t1 = in.nextInt();
		if(t1==1){
			System.out.println(n1);
		}
		else{

			BigInteger k=new BigInteger(""+k1);
			BigInteger b=new BigInteger(""+b1);
			BigInteger t=new BigInteger(""+t1);
			BigInteger z = BigInteger.ONE;

		while(z.compareTo(t)<1) {
			z=z.multiply(k);
			z=z.add(b);
			n1--;
		}
		if(n1<0){
			System.out.println(0);
		}
		else{
		System.out.println(++n1);
		}

		}

	}

}

import java.util.Scanner;

public class Bacteria {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        ;
        long t = sc.nextLong();
        long sec = 0;
        long help = 1;
        if (t == 1) {
            System.out.println(n);
            return;
        }
        while (help <= t) {
            sec++;
            help = k * help + b;
        }
        if (n + 1 - sec <= 0) {
            System.out.println(0);
        } else {
            System.out.println(n + 1 - sec);
        }
    }
}

import java.io.*;
import java.util.*;

public class Main {

	Scanner in;
	static PrintWriter out;

	static class Scanner {
		StreamTokenizer in;

		Scanner(InputStream is) {
			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
			  in.resetSyntax();
		         in.whitespaceChars(0, 32);
		         in.wordChars(33, 255);

		}

		int nextInt() {
			try {
				in.nextToken();
				return Integer.parseInt(in.sval);
			} catch (IOException e) {
				throw new Error();
			}
		}

		String next() {
			try {
				in.nextToken();
				return in.sval;
			} catch (IOException e) {
				throw new Error();
			}
		}
	}

	void solve() {
		long k = in.nextInt();
		long b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();

		long has = k + b;
		int remain = n;
		while (t >= has) {
			remain--;
			has = k * has + b;
		}
		out.println(Math.max(0, remain));
	}

	static void asserT(boolean e) {
		if (!e) {
			throw new Error();
		}
	}

	public void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;

public class Microb implements Runnable {

    final static String taskname = "filename";

    public void solve() throws Exception {

    	String input[] = in.readLine().split(" +");
    	long k = Integer.parseInt(input[0]);
    	long b = Integer.parseInt(input[1]);
    	long n = Integer.parseInt(input[2]);
    	long t = Integer.parseInt(input[3]);

    /*	BigInteger z = BigInteger.ONE;
    	  for ( int i=0 ; i < n; i++){
    		  z = z.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    	  }
    	BigInteger cur = BigInteger.valueOf(t);
    	int  res = 0;
    	  while ( cur.compareTo(z) <= 0) {
    		  cur = cur.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    		  res++;
    	  }   */
    	double delta = 0;
    	if (k==1){

    		delta = Math.floor((t-1)/b);

    	}

    	if ( k > 1) {
    		long up = b+(k-1)*t;
    		long down = k-1+b;

    		delta =  (double) up/(double)down;

    	//delta = (b*k+(k-1)*t)/(k-1+b);

    	delta = Math.log(delta)/Math.log(k);

    	// delta = (Math.floor(delta)== delta) ? (delta -1) : Math.floor(delta);

    	delta = Math.floor(delta);
    	}

    	int res = (int) (n - delta);

    	 if ( res < 0 ) res =0;

    	  out.write(res+"\n");

    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
//             in = new BufferedReader(new FileReader(taskname + ".in"));
//             out = new BufferedWriter(new FileWriter(taskname + ".out"));
            solve();
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public int iread() throws Exception {
        return Integer.parseInt(readword());
    }

    public double dread() throws Exception {
        return Double.parseDouble(readword());
    }

    public long lread() throws Exception {
        return Long.parseLong(readword());
    }

    BufferedReader in;

    BufferedWriter out;

    public String readword() throws IOException {
        StringBuilder b = new StringBuilder();
        int c;
        c = in.read();
        while (c >= 0 && c <= ' ')
            c = in.read();
        if (c < 0)
            return "";
        while (c > ' ') {
            b.append((char) c);
            c = in.read();
        }
        return b.toString();
    }

    public static void main(String[] args) {
        // Locale.setDefault(Locale.US);
        new Thread(new Microb()).start();
    }
}

import java.io.*;
import java.util.*;

public class AboutBacteria {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        long x = 1;
        int time = 0;
        while (x <= t) {
            x = k*x+b;
            time++;
        }
        System.out.println(Math.max(0,n-time+1));
    }
}

import java.io.*;
import java.util.Locale;
import java.util.StringTokenizer;

public class B implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    double readDouble() {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int size) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new B().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private int aiverson(boolean good) {
        return good ? 1 : 0;
    }

    private void solve() {
        int k = readInt();
        int b = readInt();
        int n = readInt();
        int t = readInt();
        long cur = 1;
        for (int i = 1; ; i++) {
            cur = cur * k + b;
            if (cur > t) {
                out.println(Math.max(0, n - i + 1));
                return;
            }
        }
    }
}

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int k = in.readInt();
        int b = in.readInt();
        int n = in.readInt();
        int t = in.readInt();
        long current = 1;
        for (int i = 0; i < n; i++) {
            current = current * k + b;
            if (current > t) {
                out.printLine(n - i);
                return;
            }
        }
        out.printLine(0);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        solve();
        out.close();
    }

    private static  long power(long a, long b)
    {
        long result = 1;
        for (; b > 0; a *= a, b >>= 1)
            if ((b & 1) != 0)
                result *= a;
        return result;
    }

    private static void solve()
    {
        long k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in.nextInt();

        if (k == 1)
        {
            long answer = (n * b - t + 1) / b;
            if ((n * b - t + 1) % b != 0)
                answer++;

            out.println(max(0, answer));
            return;
        }

        double max = (t * k - t + b) / (double)(k + b - 1);

        for (long x = n; x >= 0; x--)
        {
            if (max < power(k, n - x))
            {
                out.println(x + 1);
                return;
            }
        }
        out.println(0);
    }

}

import java.util.Scanner;
public class Bacteria{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long k=sc.nextLong();
        long b=sc.nextLong();
        long n=sc.nextLong();
        long t=sc.nextLong();
        long z=1;
        long T=0;
        if(t==1){
            System.out.println(n);
        }else{
            while(z<=t){
                z =z *k+b;
                T++;
            }
            T--;
            if(T<n){
            System.out.println(n-T);
            }else{
                System.out.println(0);
            }
        }
    }

}

import java.util.Scanner;

public class round125C {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double k = sc.nextDouble();
		double b = sc.nextDouble();
		double n = sc.nextDouble();
		double t = sc.nextDouble();
		double val = 0.0;
		if(k == 1){
			val = t - 1;
			val /= b;
			int min = (int)1e9;
			for(int i = 0 ; i <= n ; ++i){
				if(n - i <= val){
					min  = Math.min(min, i);
				}
			}
			System.out.println(min);
			return;
		}
		val = ((t * (k - 1)) + b) / ((k - 1) + b);
		int min = (int)1e9;
		for(int i = 0 ; i <= n ; ++i){
			if(Math.pow(k, i) <= val){
				min = Math.min(min, (int)n - i);
			}
		}
		System.out.println(min);
	}
}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        solve();
        out.close();
    }
    private static void solve()
    {
        int k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in.nextInt();

        // Find the first number that is greater than t and that is your answer
        long cur = 1;
        for (int i = 0; i < n; i++)
        {
            cur = k * cur + b;

            if (cur > t)
            {
                out.println(n - i);
                return;
            }
        }
        out.println(0);
    }

}

//package CodeForces;

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		double k=s.nextInt();double b=s.nextInt();double n=s.nextInt();double t=s.nextInt();
		if(k==1)
		{
			if(t>=1+n*b)
			{
				System.out.println(0);
			}
			else
			{
				double ans=(((1+n*b-t)*(1.0))/((b)*1.0));
				for(int i=0;;)
				{
					if(i>=ans)
					{
						System.out.println(i);
						break;
					}
					else
					{
						i++;
					}
				}
			}
		}
		else
		{
			double ans=(((t*(k-1)+b)*(1.0))/((k-1+b)*(1.0)));
			for(int i=0;;)
			{
				if(Math.pow(k,n-i)>ans)
				{
					i++;
				}
				else
				{
					System.out.println(i);
					break;
				}
			}
		}

	}

}

import java.util.Scanner;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {

            int  k=sc.nextInt();
            int b=sc.nextInt();
            int n=sc.nextInt();
            int t=sc.nextInt();
            BigInteger x=new BigInteger("1");
            BigInteger y=BigInteger.valueOf(t);
            int i=0;
            for (i=0;i<n;i++){
                x=(BigInteger.valueOf(k).multiply(x)).add(BigInteger.valueOf(b));
                if(x.compareTo(BigInteger.valueOf(t))>0){
                    break;
                }
            }
            int seconds=n-i;
            System.out.println(seconds);

        }
    }
}

/**
 *
 *

 * Unsolved - math
 *

 *

 * Created on Jun 22, 2012, 11:55:52 AM
 *

 * @Author Andy Y.F. Huang
 */
public class p199CAboutBacteria {
  private Input in;
  private Output out;

  void solve() {
    in = new Input();
    out = new Output();
    solve(1);
    out.print();
  }

  void solve(int test_number) {
    int k = in.nextInt();
    int b = in.nextInt();
    int n = in.nextInt();
    int t = in.nextInt();
    long cur = 1;
    int cnt = 0;
    while (cur <= t) {
      cnt++;
      cur = k * cur + b;
    }
    out.appendln(Math.max(0, n - cnt + 1));
  }

  public static void main(String[] args) {
    p199CAboutBacteria solver = new p199CAboutBacteria();
    solver.solve();
  }

  static void pln(Object... obj) {
    pf(obj);
    System.out.println();
  }

  static void pf(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        System.out.print(' ');
      System.out.print(obj[i]);

    }
  }
}

final class Input {
  private java.io.BufferedReader reader;
  private java.util.StringTokenizer tokenizer;
  private final String filename;
  private static final String k_default_filename = "input.txt";

  Input() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setIn(new java.io.FileInputStream(filename));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    reader = new java.io.BufferedReader(
        new java.io.InputStreamReader(System.in));
    tokenizer = new java.util.StringTokenizer("");
  }

  Input(String filename) {
    this.filename = filename;
    try {
      reader = new java.io.BufferedReader(new java.io.FileReader(this.filename));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    tokenizer = new java.util.StringTokenizer("");
  }

  String next() {
    while (!tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      }
      catch (java.io.IOException e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  String nextLine() {
    try {
      return reader.readLine();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException(e);
    }
  }

  long nextLong() {
    return Long.parseLong(next());
  }

  int nextInt() {
    return Integer.parseInt(next());
  }

  double nextDouble() {
    return Double.parseDouble(next());
  }

}

final class Output {
  private StringBuilder buffer;
  private final String filename;
  private static final String k_default_filename = "output.txt";

  Output(String filename) {
    this.filename = filename;
    try {
      System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
          this.filename)));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    buffer = new StringBuilder(1 << 16);
  }

  Output() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
            filename)));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    buffer = new StringBuilder(1 << 16);
  }

  void print() {
    System.out.print(buffer.toString());
  }

  void flush() {
    System.out.flush();
  }

  void append(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        buffer.append(' ');
      buffer.append(obj[i]);
    }
  }

  void appendln(Object... obj) {
    append(obj);
    buffer.append('\n');
  }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sarthakmanna
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        AAboutBacteria solver = new AAboutBacteria();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAboutBacteria {
        public void solve(int testNumber, FastReader in, FastWriter out) {
            int i, j, k;

            double K = in.nextLong(), B = in.nextLong(), N = in.nextLong(), T = in.nextLong();

            if (K == 1) {
                out.println(Math.max(0, (long) Math.ceil((1 + B * N - T) / B)));
                out.flush();
                return;
            }

            double ans = Math.max(0, Math.log10((K - 1 + B) / (T * K - T + B)) / Math.log10(K) + N);
            out.println((long) Math.ceil(ans));

            out.flush();
        }

    }

    static class FastReader {
        static private byte[] buf = new byte[2048];
        static private int index;
        static private int total;
        static private InputStream in;

        public FastReader(InputStream is) {
            try {
                in = is;
            } catch (Exception e) {
            }
        }

        private int scan() {
            try {
                if (index >= total) {
                    index = 0;
                    total = in.read(buf);
                    if (total <= 0)
                        return -1;
                }
                return buf[index++];
            } catch (Exception e) {
                return 7 / 0;
            }
        }

        public long nextLong() {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+')
                c = scan();
            for (; c >= '0' && c <= '9'; c = scan())
                val = (val << 3) + (val << 1) + (c & 15);
            return neg ? -val : val;
        }

    }

    static class FastWriter {
        static private BufferedWriter bw;

        public FastWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        public FastWriter(Writer w) {
            bw = new BufferedWriter(w);
        }

        public void print(Object a) {
            try {
                bw.write(a.toString());
            } catch (Exception e) {
            }
        }

        public void println(Object a) {
            print(a);
            print("\n");
        }

        public void flush() {
            try {
                bw.flush();
            } catch (Exception e) {
            }
        }

        public void close() {
            try {
                bw.close();
            } catch (Exception e) {
            }
        }

    }
}

import java.util.Scanner;

public class AboutBacteria199C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k, b, n, t;
		k = in.nextInt();
		b = in.nextInt();
		n = in.nextInt();
		t = in.nextInt();
		long z = 1;
		int a = 0;
		while (z <= t) {
			a++;
			z = z * k + b;
		}
		int m = n - a + 1;
		if (m < 0)
			m = 0;
		System.out.println(m);
	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            long k = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();
            long t = in.nextLong();

            long current = k + b;
            while (current <= t)
            {
                n--;
                current = k * current + b;
            }
            out.println(Math.max(0, n));

        }

    }
}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, a, i;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		a = 1;
		for(i=-1; a <= t && i < n; ++i) {
			a = k*a + b;
		}

		System.out.println(n-i);
	}

}

//package contest_125_div2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
/**
 * Date     : Jul 8, 2012
 * Time     : 1:37:38 PM
 * Email    : denys.astanin@gmail.com
 */

public class C {
	public static void main(String[] args) throws IOException {
		new C().run();
	}

	int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	String nextString() throws IOException {
		in.nextToken();
		return (String) in.sval;
	}

	StreamTokenizer in;
	Writer writer;
	Reader reader;

	void run() throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		reader = oj ? new InputStreamReader(System.in, "ISO-8859-1")
				: new FileReader("src/contest_125_div2/C.txt");
		writer = new OutputStreamWriter(System.out, "ISO-8859-1");
		in = new StreamTokenizer(new BufferedReader(reader));
		PrintWriter out = new PrintWriter(writer);
		int k = nextInt();
		int b = nextInt();
		int n = nextInt();
		int t = nextInt();

	    long result=1;
	    long time=0;
		while(result <= t && time < n){
	        result = result * k+b;
	        time++;
	    }
	    if(result<=t){
	    	out.println(0);
	    } else {
	    	out.println(n-(time-1));
	    }
		out.flush();
		out.close();
	}
}

import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner in = new Scanner(System.in);
	    long k = in.nextLong();
	   long b = in.nextLong();
	    long n = in.nextLong();
	    long t = in.nextLong();
	    long n1=n;
	   long  x = 1;
	    while( n>0)
	    {
	        x = k*x+b ;
	        n--;
	    }
	    long z  = 1, time=0;
	    while(z<t)
	    {
	        z = z*k +b;
	        time++;
	    }
	    if(t==1)
	    System.out.println(n1);
	    else if(time >n1)
	    System.out.println(0);
	    else
	    {if(z==t)
	    System.out.println(n1-time);
	    else
	    System.out.println(n1-time+1);}

	}
}

import java.io.*;
import java.util.*;

public class Main {
    void solve() throws IOException {
        long k = readInt(), b = readInt(), n = readInt(), t = readInt();
        int ans = 0;
        long cur = 1;
        if (t == 1) {
            out.print(n);
            return;
        }
        while (t >= cur) {
            cur *= k;
            cur += b;
            ans--;
        }
        ans += n + 1;
        out.print(maxInt(ans, 0));
    }

    int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    double getSqrt(double x, int itr) {
        double l = 0;
        double r = x;
        double m;
        while (itr-- > 0) {
            m = (l + r) / 2;
            if (m * m > x) r = m;
            else l = m;
        }
        return l;
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
        tok = new StringTokenizer("");
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) this.inc(i, a[i]);
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) t[i] += delta;
        }

        long getSum(int r) {
            long sum = 0;
            for (; r >= 0; r = (r & (r + 1)) - 1) sum += this.t[r];
            return sum;
        }

    }

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;
            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++)
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        return a;
    }

    int[] readIntArrayWithDec(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++)
            try {
                a[i] = readInt() - 1;
            } catch (IOException e) {
                e.printStackTrace();
            }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];
        for (int index = 0; index < size; ++index) array[index] = readInt();
        Arrays.sort(array);
        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) sortedArray[index] = array[index];
        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) array[index] = readInt();
        Arrays.sort(array);
        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) sortedArray[index] = array[index];
        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) min = Math.min(min, value);
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) max = Math.max(max, value);
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) min = Math.min(min, value);
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) max = Math.max(max, value);
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    double abs(double a) {
        if (a < 0) return -a;
        return a;
    }
}

// practice with kaiboy
import java.io.*;
import java.util.*;

public class CF199C extends PrintWriter {
	CF199C() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF199C o = new CF199C(); o.main(); o.flush();
	}

	void main() {
		int k = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int t = sc.nextInt();
		if (k == 1) {
			long d = 1 + (long) n * b - t;
			println(d <= 0 ? 0 : (d + b - 1) / b);
		} else {
			int m = 0;
			long c = 1;
			while (c <= t) {
				m++;
				c = c * k + b;
			}
			println(Math.max(n - m + 1, 0));
		}
	}
}

import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
int t = sc.nextInt();

long count = 1;
for (int i=0; i<n; i++){
  count*=k;
  count+=b;
  if (count>t){System.out.println(n-i); System.exit(0);}
}
System.out.println(0);

}
}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        solve();
        out.close();
    }
    private static void solve()
    {
        double k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in.nextInt();
        if (k == 1) // log base k of anything is undefined
        {
            out.println(max(0, (long)ceil((n * b - t + 1) / b)));
            return;
        }
        // A lot of algebra was used to come up with this formula ;)
        double ans = n + logBase(k, k + b - 1) - logBase(k, t * k - t + b);
        ans -= 2e-14; // Prevents stupid double precision errors

        ans = ceil(ans);
        out.println(max((long) ans, 0));
    }
    private static double logBase(double a, double b)
    {
        return log(b) / log(a);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main5 {
public static void main(String[] args) throws IOException {
    BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
    String input="";
    input =reader.readLine();
    long k=0;
    long b=0;
    long n=0;
    long t=0;
    String []array;
    long result=0;
    long time=0;
    while(input!=null){
        result=1;
        time=0;
    array=input.split(" ");
    k=Integer.parseInt(array[0]);
    b=Integer.parseInt(array[1]);
    n=Integer.parseInt(array[2]);
    t=Integer.parseInt(array[3]);
    while(result<=t&&time<n){
        result=result*k+b;
        time++;
    }
    if(result<=t){
    System.out.println(0);
    }else
    System.out.println(n-(time-1));
    input=reader.readLine();
    }
}
}

import java.util.Scanner;
public class Main {
	static Scanner sc;
	static int k,b,n,t;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		k = sc.nextInt(); //
		b = sc.nextInt(); //
		n = sc.nextInt();
		t = sc.nextInt();
		long z=1;
		int i=0;
		for(; z<=t; i++){
			z = k * z + b;
		}
		System.out.println(Math.max(0, n - i +1 ));
	}
}

import java.util.Scanner;
public class Main {
public static void main(String args[])
{
int k,b,n,t,day=0;
Scanner input=new Scanner(System.in);
k=input.nextInt();
b=input.nextInt();
n=input.nextInt();
t=input.nextInt();
long cell=1;
for( int i=0;i<n;i++)
{
    cell=(cell*k)+b;
    if(cell>t)
    {
        System.out.println(n-i);
        return;
    }
}
System.out.print("0");
    input.close();
}
}

import java.util.*;
import java.io.*;
import java.math.*;

public class c_beta extends Thread {

	BufferedReader bf;
	PrintWriter out;
	FastScanner in;

	void solve() throws Exception {
		int k = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();

		long x = 1;
		while (n > 0){
			x = x*k + b;
			if (x > t) break;
			n--;
		}
		out.println(n);
	}

	public void run() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			in = new FastScanner(bf);
			solve();
			out.flush();
		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			out.close();
		}
	}

	public static void main(String args[]) {
		new c_beta().start();
	}

	class FastScanner {
		BufferedReader bf;
		StringTokenizer st;

		public FastScanner(BufferedReader bf) {
			this.bf = bf;
		}

		public String nextToken() throws Exception {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(bf.readLine());
			}
			return st.nextToken();
		}

		public int nextInt() throws Exception {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() throws Exception {
			return Long.parseLong(nextToken());
		}

		public Double nextDouble() throws Exception {
			return Double.parseDouble(nextToken());
		}

		public BigInteger nextBigInteger() throws Exception {
			return new BigInteger(nextToken());
		}
	}
}

import java.util.Scanner;

public class bacteria {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        long k = r.nextInt();
        long b = r.nextInt();

        long n = r.nextInt();
        long t = r.nextInt();

        int counter = 0;
        long curr = 1;
        while(true){
            if(t == curr){
                System.out.println(Math.max(0, n - counter));
                return;
            }else if(curr > t){
                System.out.println(Math.max(0, 1 + n - counter));
                return;
            }

            curr = k * curr + b;
            counter++;
        }

    }
}

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class AboutBacteria implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    long k = in.nl(), b = in.nl();
    int n = in.ni(), t = in.ni();
    long current = k + b;
    while (current <= t) {
      n--;
      current = current * k + b;
      if (n == 0) break;
    }
    out.println(n);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (AboutBacteria instance = new AboutBacteria()) {
      instance.solve();
    }
  }
}

import java.io.*;
import java.util.*;

public class AboutBacteria {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        long x = 1;
        int time = 0;
        while (x <= t) {
            x = k*x+b;
            time++;
        }
        System.out.println(Math.max(0,n-time+1));
    }
}

import java.math.BigInteger;
import java.util.Scanner;
//http://www.codeforces.com/problemset/problem/198/A
public class About_Bacteria {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long k1 = in.nextInt();
		long b1 = in.nextInt();
		long n1 = in.nextInt();
		long t1 = in.nextInt();
		if(t1==1){
			System.out.println(n1);
		}
		else{

			BigInteger k=new BigInteger(""+k1);
			BigInteger b=new BigInteger(""+b1);
			BigInteger t=new BigInteger(""+t1);
			BigInteger z = BigInteger.ONE;

		while(z.compareTo(t)<1) {
			z=z.multiply(k);
			z=z.add(b);
			n1--;
		}
		if(n1<0){
			System.out.println(0);
		}
		else{
		System.out.println(++n1);
		}

		}

	}

}

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	static Scanner scan = new Scanner (System.in);
	static PrintStream out = System.out;
	static long k, b, n, t;

	static long check_nt (long X, long Y, long Z) {
		if (Y > X)
			return 0;
		long ans = 0, tmp = Y;
		while (tmp < X) {
			tmp *= Z;
			++ans;
		}
		return (tmp > X)?(ans-1):ans;
	}

	static void go () {
		long nt = 0;
		if (k == 1) {
			nt = (t-1)/b;
			System.out.println (Math.max(0, n-nt));
			return;
		}
		long X = (k-1)*t+b, Y = k+b-1, Z = k;
		nt = check_nt (X, Y, Z);
		System.out.println (Math.max (0, n - nt));

	}

	public static void main (String[] args) {
		k = scan.nextLong();
		b = scan.nextLong();
		n = scan.nextLong();
		t = scan.nextLong();

		go ();
	}

}

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner myScan = new Scanner(System.in);
		int k = myScan.nextInt();
		int b = myScan.nextInt();
		int n = myScan.nextInt();
		int t = myScan.nextInt();
		long z = 1;
		boolean flag=false;
		for (int i = 0; i < n; i++) {
			z = z * k + b;
			if (z > t) {
				System.out.println(n - i);
				flag=true;
				break;
			}
		}
		if(!flag)
		System.out.println(0);

	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AboutBacteria {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());

        long x = 1;
        int seconds = 0;
        for (int i = 0; i < n; i++) {
            x = k * x + b;
            if(x <= t)
                seconds++;
            else
                break;
        }

        System.out.println(n - seconds);
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author sarthakmanna
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        FastWriter out = new FastWriter(outputStream);
        AAboutBacteria solver = new AAboutBacteria();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAboutBacteria {
        public void solve(int testNumber, FastReader in, FastWriter out) {
            int i, j, k;

            double K = in.nextLong(), B = in.nextLong(), N = in.nextLong(), T = in.nextLong();

            if (K == 1) {
                out.println(Math.max(0, (long) Math.ceil((1 + B * N - T) / B)));
                out.flush();
                return;
            }

            double ans = Math.max(0, Math.log((K - 1 + B) / (T * K - T + B)) / Math.log(K) + N);
            out.println((long) Math.ceil(ans));

            out.flush();
        }

    }

    static class FastReader {
        static private byte[] buf = new byte[2048];
        static private int index;
        static private int total;
        static private InputStream in;

        public FastReader(InputStream is) {
            try {
                in = is;
            } catch (Exception e) {
            }
        }

        private int scan() {
            try {
                if (index >= total) {
                    index = 0;
                    total = in.read(buf);
                    if (total <= 0)
                        return -1;
                }
                return buf[index++];
            } catch (Exception e) {
                return 7 / 0;
            }
        }

        public long nextLong() {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+')
                c = scan();
            for (; c >= '0' && c <= '9'; c = scan())
                val = (val << 3) + (val << 1) + (c & 15);
            return neg ? -val : val;
        }

    }

    static class FastWriter {
        static private BufferedWriter bw;

        public FastWriter(OutputStream os) {
            bw = new BufferedWriter(new OutputStreamWriter(os));
        }

        public FastWriter(Writer w) {
            bw = new BufferedWriter(w);
        }

        public void print(Object a) {
            try {
                bw.write(a.toString());
            } catch (Exception e) {
            }
        }

        public void println(Object a) {
            print(a);
            print("\n");
        }

        public void flush() {
            try {
                bw.flush();
            } catch (Exception e) {
            }
        }

        public void close() {
            try {
                bw.close();
            } catch (Exception e) {
            }
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C implements Runnable {

	private void Solution() throws IOException {
		int k = nextInt(), b = nextInt(), n = nextInt(), t = nextInt();
		long cur = 1;
		while (n > 0) {
			cur = k * cur + b;
			if (cur > t)
				break;
			n--;
		}
		print(n < 0 ? 0 : n);
	}

	public static void main(String[] args) {
		new C().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tokenizer;

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			Solution();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
	}

	void print(Object... obj) {
		for (int i = 0; i < obj.length; i++) {
			if (i != 0)
				out.print(" ");
			out.print(obj[i]);
		}
	}

	void println(Object... obj) {
		print(obj);
		print("\n");
	}

	int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(next());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(next());
	}

	String nextLine() throws IOException {
		return in.readLine();
	}

	String next() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}
}

import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class A198
{

	public static int mod = 1000000007;
	public static long INF = (1L << 60);
	static FastScanner2 in = new FastScanner2();
	static OutputWriter out = new OutputWriter(System.out);

	public static void main(String[] args)
	{

		long k=in.nextLong();
		long b=in.nextLong();
		long n=in.nextLong();
		long t=in.nextLong();
		if(k==1)
		{
			out.println((long)ceil((double)(n*b+1-t)/(double)b)>0?(long)ceil((double)(n*b+1-t)/(double)b):0);
			out.flush();
			return;
		}
		else
		{
			double val=(double)(t*(k-1)+b)/(double)(k-1+b);
			for(int i=0;i<=n;i++)
			{
				long power=pow(k, n-i);
				if(power<=val && power>0)
				{
					out.println(i);
					out.flush();
					return;
				}
			}
		}
		out.close();

	}

	public static long pow(long x, long n)
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p))
		{
			if ((n & 1) != 0)
			{
				res = (res * p);
			}
		}
		return res;
	}

	public static long pow(long x, long n, long mod)
	{
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod)
		{
			if ((n & 1) != 0)
			{
				res = (res * p % mod);
			}
		}
		return res;
	}

	public static long gcd(long n1, long n2)
	{
		long r;
		while (n2 != 0)
		{
			r = n1 % n2;
			n1 = n2;
			n2 = r;
		}
		return n1;
	}

	public static long lcm(long n1, long n2)
	{
		long answer = (n1 * n2) / (gcd(n1, n2));
		return answer;
	}

	static class FastScanner2
	{
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

		public int read()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = System.in.read(buf);
				} catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isEndOfLine(c));
			return res.toString();
		}

		public String nextString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));
			return res.toString();
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public int nextInt()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int[] arr = new int[n];
			for (int i = 0; i < n; i++)
			{
				arr[i] = nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n)
		{
			long[] arr = new long[n];
			for (int i = 0; i < n; i++)
			{
				arr[i] = nextLong();
			}
			return arr;
		}

		private boolean isSpaceChar(int c)
		{
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	static class InputReader
	{
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream)
		{
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine()
		{
			String fullLine = null;
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					fullLine = reader.readLine();
				} catch (IOException e)
				{
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}

		public String next()
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public long nextLong()
		{
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n)
		{
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextLong();
			}
			return a;
		}

		public int nextInt()
		{
			return Integer.parseInt(next());
		}
	}

	static class OutputWriter
	{
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream)
		{
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer)
		{
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects)
		{
			for (int i = 0; i < objects.length; i++)
			{
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void println(Object... objects)
		{
			print(objects);
			writer.println();
		}

		public void close()
		{
			writer.close();
		}

		public void flush()
		{
			writer.flush();
		}
	}

}

import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.Math.*;

public class Main implements Runnable {

	void solve() throws Exception {
		int k = sc.nextInt(), b = sc.nextInt(), n = sc.nextInt(), t = sc.nextInt();
		long x = 1;
		int answer = 0;
		while (k * x + b <= t) {
			answer++;
			x = k * x + b;
		}
		//out.println(answer);
		out.println(max(0, n - answer));
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			//System.setOut(new PrintStream("test.txt"));
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Main.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Main(), "", 128 * 1024 * 1024);
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

	public String nextToken() throws IOException {
		while (strTok == null || !strTok.hasMoreTokens()) {
			strTok = new StringTokenizer(reader.readLine());
		}
		return strTok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

}

import java.util.*;

public class cbc {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int b = input.nextInt();
        int n = input.nextInt();
        int t = input.nextInt();
        long X= 1;
        for(int i = 0; i < n; i++)
        {
            X= X*k+b;
            if(X>t)
            {
                System.out.println(n-i);
                return;
            }
        }
        System.out.println(0);
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            long k = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();
            long t = in.nextLong();

            long current = k + b;
            while (current <= t)
            {
                n--;
                current = k * current + b;
            }
            out.println(Math.max(0, n));

        }

    }
}

import java.io.*;
import java.util.*;

public class Main {

	Scanner in;
	static PrintWriter out;

	static class Scanner {
		StreamTokenizer in;

		Scanner(InputStream is) {
			in = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
			  in.resetSyntax();
		         in.whitespaceChars(0, 32);
		         in.wordChars(33, 255);

		}

		int nextInt() {
			try {
				in.nextToken();
				return Integer.parseInt(in.sval);
			} catch (IOException e) {
				throw new Error();
			}
		}

		String next() {
			try {
				in.nextToken();
				return in.sval;
			} catch (IOException e) {
				throw new Error();
			}
		}
	}

	void solve() {
		long k = in.nextInt();
		long b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();

		long has = k + b;
		int remain = n;
		while (t >= has) {
			remain--;
			has = k * has + b;
		}
		out.println(Math.max(0, remain));
	}

	static void asserT(boolean e) {
		if (!e) {
			throw new Error();
		}
	}

	public void run() {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);

		try {
			solve();
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
int t = sc.nextInt();

long count = 1;
for (int i=0; i<n; i++){
  count*=k;
  count+=b;
  if (count>t){System.out.println(n-i); System.exit(0);}
}
System.out.println(0);

}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(
                System.in));
        StringBuffer str = new StringBuffer();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer s = new StringTokenizer(input.readLine());
        int k = Integer.parseInt(s.nextToken());
        int b = Integer.parseInt(s.nextToken());
        int n = Integer.parseInt(s.nextToken());
        int t = Integer.parseInt(s.nextToken());
        BigInteger z = BigInteger.valueOf(1);
        while (z.compareTo(new BigInteger(t + "")) < 1) {
            z = z.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
            n--;
        }
        if (n < 0) {
            out.println("0");
        } else {
            out.println(n + 1);
        }

        out.close();

    }

}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int k = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int t = sc.nextInt();

		long cur = 1;
		int p = 0;
		long mult = 1;

		for (int i = 1; i <= n; i++) {
			cur += 1l * (b - 1) * mult;
			mult *= k;
			cur += mult;
			if(cur > t)
				break;
			p++;
		}

		out.println(n - p);

		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
		public Scanner(String file) throws FileNotFoundException{	br = new BufferedReader(new FileReader(file));}

		public String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}
		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AboutBacteria {

	public static void main(String[] args) throws IOException {
		long k, b, n, t, m, zm = 1;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		k = Integer.parseInt(st.nextToken());
		b = Integer.parseInt(st.nextToken());
		n = Integer.parseInt(st.nextToken());
		t = Integer.parseInt(st.nextToken());

		for (m = 0; m < n && zm < t; ++m)
	        zm = k * zm + b;
	    if (zm > t)
	        m--;

	    System.out.println(n - m);
	}

}

//package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class A implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    A() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("output.txt"));
    }

    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    private int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    int inv(int x) {
        return pow(x, MOD - 2);
    }

    void solve() throws IOException {
        int k = nextInt(), b = nextInt(), n = nextInt(), t = nextInt();
        long x = 1;
        int catchUpTime = 0;
        while(x < t) {
            x = k * x + b;
            catchUpTime++;
        }
        int answer = x == t ? n - catchUpTime : n - catchUpTime + 1;
        answer = Math.max(0, answer);
        writer.println(answer);
    }

    public static void main(String[] args) throws IOException {
        try (A a = new A()) {
            a.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}

//package CodeForces;

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		double k=s.nextInt();double b=s.nextInt();double n=s.nextInt();double t=s.nextInt();
		if(k==1)
		{
			if(t>=1+n*b)
			{
				System.out.println(0);
			}
			else
			{
				double ans=(((1+n*b-t)*(1.0))/((b)*1.0));
				for(int i=0;;)
				{
					if(i>=ans)
					{
						System.out.println(i);
						break;
					}
					else
					{
						i++;
					}
				}
			}
		}
		else
		{
			double ans=(((t*(k-1)+b)*(1.0))/((k-1+b)*(1.0)));
			for(int i=0;;)
			{
				if(Math.pow(k,n-i)>ans)
				{
					i++;
				}
				else
				{
					System.out.println(i);
					break;
				}
			}
		}

	}

}

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Erik Odenman
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
        int k = in.getInt();
        int b = in.getInt();
        int n = in.getInt();
        long t = in.getInt();
        int res = n;
        long kPart = 1;
        long bPart = 0;
        while (true) {
            bPart = bPart*k+b;
            kPart *= k;
            if (res == 0 || t < kPart + bPart) {
                break;
            }
            res--;
        }
        out.println(res);
	}
}

class InputReader {
    private BufferedReader in;
    private StringTokenizer st;
    String token;

    public InputReader(InputStream inStream) {
        in = new BufferedReader(new InputStreamReader(inStream));
    }

    public int getInt() {
        return Integer.parseInt(next());
    }

    public String next() {
        String res = peekToken();
        token = null;
        return res;
    }

    public String peekToken() {
        if (token != null) return token;
        while (st == null || !st.hasMoreTokens()) {
            String line = null;
            try {
                line = in.readLine();
            } catch (IOException e) {
                throw new RuntimeException("No more tokens was found");
            }
            if (line == null) return null;
            st = new StringTokenizer(line);
        }
        return token = st.nextToken();
    }

    }

class OutputWriter  {

    PrintWriter out;

    public OutputWriter(OutputStream outStream) {
        out = new PrintWriter(outStream);
    }

    public OutputWriter(Writer writer) {
        out = new PrintWriter(writer);
    }

    public void print(Object... objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0) out.print(' ');
            out.print(objects[i]);
        }
    }

    public void println(Object... objects) {
        print(objects);
        out.println();
    }

    public void close() {
        out.close();
    }
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long k = input.nextLong();
        long b = input.nextLong();
        long n = input.nextLong();
        long z = input.nextLong();

        long time = -1;
        long number = 1;
        while (number <= z) {
            time++;
            number = number * k + b;

        }
        if ((n - time) >= 0)
            System.out.println(n - time);
        else
            System.out.println(0);

    }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
//      // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int k=in.nextInt();
        int b=in.nextInt();
        int n=in.nextInt();
        int t=in.nextInt();
        long r=k+b;
        int time=0;
        while(r<t+1){
            r=(k*r)+b;
            time++;
        }
        if(n-time<0){
        System.out.println("0");
        }
        else{
            System.out.println(n-time);
        }
//
    }
//
}

import java.io.*;
import java.util.*;

public class AboutBacteria {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(f.readLine());
        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        long x = 1;
        int time = 0;
        while (x <= t) {
            x = k*x+b;
            time++;
        }
        System.out.println(Math.max(0,n-time+1));
    }
}

import java.util.Scanner;

public class N4_CF_199C {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in
        .nextInt();
    long z = 1;
    for(int i = 0 ; i < n ; i++)
    {
        z = z * k * 1l + b;
        if( t <= z - 1)
        {
        System.out.println(n - i);
        return;
        }
    }
    System.out.println(0);
    }

}

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner myScan = new Scanner(System.in);
		int k = myScan.nextInt();
		int b = myScan.nextInt();
		int n = myScan.nextInt();
		int t = myScan.nextInt();
		long z = 1;
		boolean flag=false;
		for (int i = 0; i < n; i++) {
			z = z * k + b;
			if (z > t) {
				System.out.println(n - i);
				flag=true;
				break;
			}
		}
		if(!flag)
		System.out.println(0);

	}
}

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner r = new Scanner(System.in);

		double k = r.nextDouble();
		double b = r.nextDouble();

		double n = r.nextDouble();
		double t = r.nextDouble();

		if(k == 1){
			if(b == 0){
				System.out.println(0);
				return;
			}else{
				double x = (1 + b * n - t) / b;
				System.out.println(Math.max(0, (int)Math.ceil(x)));
				return;
			}
		}

		double A = (b + t * k - t) / (k - 1 + b);
//		System.out.println(A);

		double x = n - Math.log(A) / Math.log(k);

//		System.out.println(x);
		System.out.println(Math.max(0, (int)Math.ceil(x)));

	}
}

import java.util.Scanner;
public class AboutBacteria {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        long k = in.nextInt();
        long b = in.nextInt();
        long n = in.nextInt();
        long t = in.nextInt();
        long z = 1;
        while (z <= t)
        {
            z = z*k+b;
            n--;
        }

        System.out.println(Math.max(0, n + 1));
    }
}

import java.io.*;
import java.util.*;

public class Contest1_1{

    public static void main(String ar[]) throws Exception {

        BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(buff.readLine());
        long k = Long.parseLong(tok.nextToken());
        long b = Long.parseLong(tok.nextToken());
        long n = Long.parseLong(tok.nextToken());
        long t = Long.parseLong(tok.nextToken());
        long z = 1;
        int count =0;
        if(z==t){
            System.out.println(n);
        }else {
            while(z<=t && count<=n)
            {
                z = (z*k) + b;
                count++;
            }
            System.out.println(n-count+1);
        }
    }
}

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	static Scanner scan = new Scanner (System.in);
	static PrintStream out = System.out;
	static long k, b, n, t;

	static void go () {
		long nt = 0;
		if (k == 1) {
			nt = (t-1)/b;
			System.out.println (Math.max(0, n-nt));
			return;
		}
		nt = (int)Math.floor((Math.log((k-1)*t+b) - Math.log(k+b-1))/Math.log(k));
		System.out.println (Math.max (0, n - nt));

	}

	public static void main (String[] args) {
		k = scan.nextLong();
		b = scan.nextLong();
		n = scan.nextLong();
		t = scan.nextLong();

		go ();
	}

}

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	static Scanner scan = new Scanner (System.in);
	static PrintStream out = System.out;
	static long k, b, n, t;

	static long check_nt (long X, long Y, long Z) {
		if (Y > X)
			return 0;
		long ans = 0, tmp = Y;
		System.out.println (X + " " + Y + " " + Z);
		while (tmp < X) {
			tmp *= Z;
			++ans;
		}
		return (tmp > X)?(ans-1):ans;
	}

	static void go () {
		long nt = 0;
		if (k == 1) {
			nt = (t-1)/b;
			System.out.println (Math.max(0, n-nt));
			return;
		}
		long X = (k-1)*t+b, Y = k+b-1, Z = k;
		nt = check_nt (X, Y, Z);
		System.out.println (Math.max (0, n - nt));

	}

	public static void main (String[] args) {
		k = scan.nextLong();
		b = scan.nextLong();
		n = scan.nextLong();
		t = scan.nextLong();

		go ();
	}

}

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long k = in.nextLong();
        long b = in.nextLong();
        long n = in.nextLong();
        long t = in.nextLong();
        int answer;
        if (k == 1)
            answer = Math.max(0, (int) (n - (t - 1) / b));
        else {
            double c1 = -(t * (1 - k) - b);
            double c2 = -(1 - k - b);
            double cc = -(Math.log(c2) - Math.log(c1)) / Math.log(k);
            answer = Math.max(0, (int) (n - (int) (cc + 1e-6)));
        }
        out.println(answer);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Solver {

    StringTokenizer st;
    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws NumberFormatException, IOException {
        Solver solver = new Solver();
        solver.open();
        solver.solve();
        solver.close();
    }

    public void open() throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws NumberFormatException, IOException {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws NumberFormatException, IOException {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(nextToken());
    }

    long[][] mul(long[][] a,long[][] b){
        int m = a.length;
        int n = a[0].length;
        int q = b[0].length;

        long[][] result = new long[m][q];

        for(int i=0;i<m;i++)
            for(int j=0;j<q;j++)
                for(int k=0;k<n;k++)
                    result[i][j] +=  a[i][k]*b[k][j];

        return result;
    }

    long[][] binpow (long[][] a, int n) {
        long[][] result= new long[a.length][a.length];

        for(int i=0;i<a.length;i++)
            result[i][i] = 1;

        while (n>0)
            if ((n & 1)==1) {
                result = mul(result, a);
                n--;
            }
            else {
                a = mul(a,a);
                n /= 2;
            }
        return result;
    }

    public void solve() throws NumberFormatException, IOException {
        int k = nextInt();
        int b = nextInt();
        int n = nextInt();
        int t = nextInt();

        long[][] start = new long[2][1];
        start[0][0] = t;
        start[1][0] = 1;

        long[][] muller = new long[2][2];
        muller[0][0] = k;
        muller[0][1] = 0;
        muller[1][0] = b;
        muller[1][1] = 1;

        long[][] tmp = binpow(muller, n);

        long z = tmp[0][0]+tmp[1][0];

        int l = 0;
        int r = n;

        while (l<r){
            int c = (r+l)/2;
            long[][] tmp2 = binpow(muller,c);
            long z2 = t*tmp2[0][0]+tmp2[1][0];
            if (z2>=z){
                r = c;
            }else{
                l = c+1;
            }
        }
        out.println(l);
    }

    public void close() {
        out.flush();
        out.close();
    }

}

import java.util.Scanner;

public class AboutBacteria {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        int k = read.nextInt();
        int b = read.nextInt();
        int n = read.nextInt();
        int t = read.nextInt();
        int current = 1;
        int sec = 0;
        while (current < t) {
            current = k * current + b;
            sec++;
        }
        if (n + 1 - sec < 0)
            System.out.println(0);
        else
            System.out.println(n + 1 - sec);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nafiur Rahman Khadem Shafin
 */
public class Main {
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader (inputStream);
		PrintWriter out = new PrintWriter (outputStream);
		TaskA solver = new TaskA ();
		solver.solve (1, in, out);
		out.close ();
	}

	static class TaskA {
		public void solve (int testNumber, InputReader in, PrintWriter out) {
/* at least ==> one way can be binary search. k(k(k+b)+b)+b...==z have to find out k(kt+b)+b...>=z
 * but not that easy as you can't calculate z ==> let's try to eliminate z from above ansmax==n
 * k^x(t-k^(n-x)-(k^x+k^(x+1)+....k^(n-1))b>=0. ==> k^x(t-k^(n-x))-k^x((k^(n-x)-1)/(k-1))b>=0
 * But the formula used for geometric progression has a corner case: k==1. if (k==1) t-1-(n-x)b>=0
 * else ==> t(k-1)-k^(n-x)(k-1)-b(k^(n-x)-1)>=0 (by dividing both side by k^x/(k-1))
 * The reason behind multiplicitation by (k-1) is to avoid fraction for sure
 * ==> k^(n-x)(k-1+b)<=t(k-1)+b ==> k^(n-x)<=(t(k-1)+b)/(k-1+b)*/
			int k = in.nextInt (), b = in.nextInt (), n = in.nextInt (), t = in.nextInt ();
			long pkNminusX = 1;
			int x = n;
			if (k == 1) {
				out.println (n-(t-1)/b);
				return;
			}
			long rhs = (t*(long) (k-1)+b)/(k-1+b);
			while (pkNminusX<=rhs && x>-1) {
				pkNminusX *= k;
				x--;
			}
			out.println (x+1);
		}

	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public InputReader (InputStream stream) {
			reader = new BufferedReader (new InputStreamReader (stream));
			tokenizer = null;
		}

		public String next () {
			while (tokenizer == null || !tokenizer.hasMoreTokens ()) {
				try {
					String str;
					if ((str = reader.readLine ()) != null) tokenizer = new StringTokenizer (str);
					else return null;//to detect eof
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken ();
		}

		public int nextInt () {
			return Integer.parseInt (next ());
		}

	}
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        double k = r.nextDouble();
        double b = r.nextDouble();

        double n = r.nextDouble();
        double t = r.nextDouble();

        if(k == 1){
            if(b == 0){
                System.out.println(0);
                return;
            }else{
                double x = (1 + b * n - t) / b;
                System.out.println((int)Math.ceil(x - 1e-7));
                return;
            }
        }

        //try zero;
        double ans = Math.pow(k, n) + b  * (Math.pow(k, n) - 1) / (k - 1);
//      System.out.println(ans);
        if(Math.abs(t - ans) < 1e-7 || t > ans){
            System.out.println(0);
            return;
        }

        double A = (b + t * k - t) / (k - 1 + b);
//      System.out.println(A);

        double x = n - Math.log(A) / Math.log(k);

//      System.out.println(x);
        System.out.println((int)Math.ceil(x - 1e-7));

    }
}

/*
ID: sunits789
LANG: JAVA
TASK: C125
*/
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

public class C125 {
        public static void main(String[] args) {
                InputStream inputStream = System.in;
                OutputStream outputStream = System.out;
                InputReader in = new InputReader(inputStream);
                PrintWriter out = new PrintWriter(outputStream);
                CodeC125 solver = new CodeC125();
                int x=solver.solve(1, in, out);
                out.close();
        }
}

class CodeC125
{
public int solve(int testNumber, InputReader in, PrintWriter out)
{
	int k=in.nextInt();
	int b=in.nextInt();
	int n=in.nextInt();
	int t=in.nextInt();
	long pow[]=new long[100];
	pow[0]=1;
	if(k==1)
	{
		int z=1+n*b;
		z-=t;
		int ans=z/b;
		if(z/b!=0)
		{
			ans++;
		}
		if(ans>0)
		{
			out.println(ans);
		}
		else
		{
			out.println(0);
		}
		return 0;
	}
	for(int i=1;i<100;i++)
	{
		pow[i]=pow[i-1]*(long)k;
		// out.println(pow[i]);
	}
	int ans=n;
	long sum=0;
	for(int i=0;i<100;i++)
	{
		int m=(n-i);
		ans=m;
		if(i>0)
		{
			sum+=pow[i-1];
		}
		long check=(long)b*sum+pow[i];
		// out.println(check);
		if(check>=(long)t)
		{
			i=100;
			if(check>(long)t)
			{
				ans++;
			}
		}
	}
	if(ans>0)
	{
		out.println(ans);
	}
	else
	{
		out.println(0);
	}
	return 0;

}

}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }
	public void inputShuffleArrayInt(int arr[])
	{
		int l=arr.length;
		for(int i=0;i<l;i++)
		{
			if(i%2==0)
			{
				arr[i/2]=nextInt();
			}
			else
			{
				arr[l-((i+1)/2)]=nextInt();
			}
		}
	}

    }

import java.io.*;
import java.math.BigInteger;
import java.util.*;

 public class Main {
    static int arr[], N, K;
    static boolean adj[][];
    static BigInteger dp[][];
    static boolean reach[][];
    static  String str1 [];
     static String str2 [];
     public static void main(String[] args) throws IOException {
         Scanner sc = new Scanner(System.in);
         double k = sc.nextDouble();
         double b = sc.nextDouble();
         double n = sc.nextDouble();
         double t = sc.nextDouble();
         if(k==1){
             double z = b*n;
             n = Math.ceil((z-t)/b);
             System.out.println((int)n);
         }else{
             double z = Math.pow(k,n) + b * ((1 - Math.pow(k,n))/(1-k));
             n = Math.log((z*(1-k)-b) / ((1-k)*t - 1)) / Math.log(k);
             System.out.println((n<=0) ? "0" : (int)Math.ceil(n));
         }
     }

     static class Point
     {
         int x;
         int y;

         public Point(int x, int y)
         {
             this.x = x;
             this.y = y;
         }

     };

     // Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
     static boolean onSegment(Point p, Point q, Point r)
     {
         if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&
                 q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))
             return true;

         return false;
     }

     // To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
     static int orientation(Point p, Point q, Point r)
     {
         // See https://www.geeksforgeeks.org/orientation-3-ordered-points/
         // for details of below formula.
         int val = (q.y - p.y) * (r.x - q.x) -
                 (q.x - p.x) * (r.y - q.y);

         if (val == 0) return 0; // colinear

         return (val > 0)? 1: 2; // clock or counterclock wise
     }

     // The main function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
     static boolean doIntersect(Point p1, Point q1, Point p2, Point q2)
     {
         // Find the four orientations needed for general and
         // special cases
         int o1 = orientation(p1, q1, p2);
         int o2 = orientation(p1, q1, q2);
         int o3 = orientation(p2, q2, p1);
         int o4 = orientation(p2, q2, q1);

         // General case
         if (o1 != o2 && o3 != o4)
             return true;

         // Special Cases
         // p1, q1 and p2 are colinear and p2 lies on segment p1q1
         if (o1 == 0 && onSegment(p1, p2, q1)) return true;

         // p1, q1 and q2 are colinear and q2 lies on segment p1q1
         if (o2 == 0 && onSegment(p1, q2, q1)) return true;

         // p2, q2 and p1 are colinear and p1 lies on segment p2q2
         if (o3 == 0 && onSegment(p2, p1, q2)) return true;

         // p2, q2 and q1 are colinear and q1 lies on segment p2q2
         if (o4 == 0 && onSegment(p2, q1, q2)) return true;

         return false; // Doesn't fall in any of the above cases
     }
/*
     static class Scanner
     {
         StringTokenizer st;
         BufferedReader br;

         public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
         public Scanner(String s) throws FileNotFoundException {
             br = new BufferedReader(new FileReader(s));
         }
         public String next() throws IOException
         {
             while (st == null || !st.hasMoreTokens())
                 st = new StringTokenizer(br.readLine());
             return st.nextToken();
         }

         public int nextInt() throws IOException {return Integer.parseInt(next());}

         public String nextLine() throws IOException {return br.readLine();}

         public long nextLong() throws IOException {return Long.parseLong(next());}

         public boolean ready() throws IOException {return br.ready();}
     }

 */
 }

import java.util.*;

public class Virtual125A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt(), b = sc.nextInt(), n = sc.nextInt(), t = sc.nextInt();

		if(k==1){
			if(t>=b*n+1){
				System.out.println(0);
				return;
			}
			long ans = (((long)b)*((long)n)-t+b)/b;
			System.out.println(ans);
		}
		else{
			int ans = 0;
			long prod = 1;
			long K = k, B = b;
			while(true){
				if(prod*K*(K-1+B) <= (K-1)*t + B){
					prod *= K;
					ans++;
				}
				else break;
			}
			if(n>=ans) System.out.println(n-ans);
			else System.out.println(0);
		}
	}

}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z, exp;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double) (z-t) / b); // Minimum number of WHOLE seconds
		} else {
			// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
			n += (Math.ceil(Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.ceil(Math.log(k)));
		}

		if(n < 0) { // Already have more than enough bacteria
			n = 0;
		}

		System.out.println(n);
	}

}

import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author tengxiao
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long k=in.nextLong(),b=in.nextLong(),n=in.nextLong(),t=in.nextLong();
        long m=0;
        double tmpm=0;
        if(k==1){
            tmpm = (1+n*b-t)/(double)b;
            if(tmpm<0)
                m=0;
            else
                m=(long)Math.ceil(tmpm);
        }
        else{
            double tmp=(Math.pow(k,n)*(k+b-1))/(t*k-t+b);
            if(tmp<=1)
                m=0;
            else{
                tmp=logb(tmp,k);
                m=(long)Math.ceil(tmp);
            }
        }
        out.println(m);
	}

    public double logb( double a, double b )
    {
        return Math.log(a) / Math.log(b);
    }
}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double)(z-t) / b);
		} else {
			n = (long) Math.round((double) n - Math.log((t*(k-1)+b)/(k-1+b)) * (1 / Math.log(k)));
		}

		if(n < 0) {
			n = 0;
		}

		System.out.println(n);
	}

}

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int b = input.nextInt();
        int n = input.nextInt();
        int t = input.nextInt();
        int cur = 1;
        while(cur < t){
            cur = cur*k+b;
            n--;
        }

        if(n > 0){
            System.out.println(n+1);
        }
        else
            System.out.println(0);
    }

}

/**
 *
 *

 * Unsolved - math
 *

 *

 * Created on Jun 22, 2012, 11:55:52 AM
 *

 * @Author Andy Y.F. Huang
 */
public class p199CAboutBacteria {
  private Input in;
  private Output out;

  void solve() {
    in = new Input();
    out = new Output();
    solve(1);
    out.print();
  }

  void solve(int test_number) {
    int k = in.nextInt();
    int b = in.nextInt();
    int n = in.nextInt();
    int t = in.nextInt();
    int cur = 1;
    while (cur <= t) {
      cur = k * cur + b;
      n--;
    }
    out.appendln(Math.max(0, n + 1));
  }

  public static void main(String[] args) {
    p199CAboutBacteria solver = new p199CAboutBacteria();
    solver.solve();
  }

  static void pln(Object... obj) {
    pf(obj);
    System.out.println();
  }

  static void pf(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        System.out.print(' ');
      System.out.print(obj[i]);

    }
  }
}

final class Input {
  private java.io.BufferedReader reader;
  private java.util.StringTokenizer tokenizer;
  private final String filename;
  private static final String k_default_filename = "input.txt";

  Input() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setIn(new java.io.FileInputStream(filename));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    reader = new java.io.BufferedReader(
        new java.io.InputStreamReader(System.in));
    tokenizer = new java.util.StringTokenizer("");
  }

  Input(String filename) {
    this.filename = filename;
    try {
      reader = new java.io.BufferedReader(new java.io.FileReader(this.filename));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    tokenizer = new java.util.StringTokenizer("");
  }

  String next() {
    while (!tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      }
      catch (java.io.IOException e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  String nextLine() {
    try {
      return reader.readLine();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException(e);
    }
  }

  long nextLong() {
    return Long.parseLong(next());
  }

  int nextInt() {
    return Integer.parseInt(next());
  }

  double nextDouble() {
    return Double.parseDouble(next());
  }

}

final class Output {
  private StringBuilder buffer;
  private final String filename;
  private static final String k_default_filename = "output.txt";

  Output(String filename) {
    this.filename = filename;
    try {
      System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
          this.filename)));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    buffer = new StringBuilder(1 << 16);
  }

  Output() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
            filename)));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    buffer = new StringBuilder(1 << 16);
  }

  void print() {
    System.out.print(buffer.toString());
  }

  void flush() {
    System.out.flush();
  }

  void append(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        buffer.append(' ');
      buffer.append(obj[i]);
    }
  }

  void appendln(Object... obj) {
    append(obj);
    buffer.append('\n');
  }

}

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner r = new Scanner(System.in);

		double k = r.nextDouble();
		double b = r.nextDouble();

		double n = r.nextDouble();
		double t = r.nextDouble();

		if(k == 1){
			if(b == 0){
				System.out.println(0);
				return;
			}else{
				double x = (1 + b * n - t) / b;
				System.out.println(Math.max(0, (int)Math.ceil(x - 1e-7)));
				return;
			}
		}

		if(t == 1){
			System.out.println(n);
			return;
		}

		double A = (b + t * k - t) / (k - 1 + b);
//		System.out.println(A);

		double x = n - Math.log(A) / Math.log(k);

//		System.out.println(x);
		System.out.println(Math.max(0, (int)Math.ceil(x - 1e-7)));

	}
}

import java.math.BigInteger;
import java.util.*;

public class Bacteria {

    public static void main(String[] args) {
        Scanner ted = new Scanner(System.in);
        while (ted.hasNext()) {
            long k = ted.nextLong();
            long b = ted.nextLong();
            long n = ted.nextLong();
            long t = ted.nextLong();

            BigInteger  firstBackteria =new BigInteger("1");
            BigInteger  kk =new BigInteger(k+"");
            BigInteger  bb =new BigInteger(b+"");
            BigInteger  tt =new BigInteger(t+"");
            for (long i = 1; i <= n; i++) {
                firstBackteria = firstBackteria.add( firstBackteria.multiply(kk).add(bb));
            }
            long j = 0;
            for (j = 0; tt.compareTo(firstBackteria)<0 && t != 0;) {
                j++;
                tt = tt.add( tt.multiply(kk).add(bb));
            }
            if (t != 0)
                System.out.println(j);
            else
                System.out.println("can't");
        }

    }

}

import java.util.Scanner;

public class N4_CF_199C {
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in
        .nextInt();
    int z = 1;
    for(int i = 0 ; i < n ; i++)
    {
        z = z * k + b;
        if( t < z - 1)
        {
        System.out.println(n - i);
        return;
        }
    }
    System.out.println(0);
    }

}

import java.util.Scanner;
import java.math.*;
import java.util.*;

public class JavaAcm
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int i , k , b , n , t , sum = 1;
		k = scan.nextInt();
		b = scan.nextInt();
		n = scan.nextInt();
		t = scan.nextInt();
		i = n;
		while(sum <= t)
		{
			i --;
			sum *= 3;
		}
		if(i < 0)
	       i = 0;
		System.out.println(i);
	}
}

import java.util.*;

public class Bacteria {

    public static void main(String[] args) {
        Scanner ted = new Scanner(System.in);
        while (ted.hasNext()) {
            long k = ted.nextLong();
            long b = ted.nextLong();
            long n = ted.nextLong();
            long t = ted.nextLong();

            long firstBackteria = 1;
            for (long i = 1; i <= n; i++) {
                firstBackteria = k * firstBackteria + b;
            }
            long j = 0;
            for (j = 0; t < firstBackteria && t != 0;) {
                j++;
                t = k * t + b;
            }
            if (t != 0)
                System.out.println(j);
            else
                System.out.println("can't");
        }

    }

}

import java.util.*;
import java.io.*;
import java.math.*;
public class Euler {

    public static void main(String[] args){
        FastReader in = new FastReader();
        PrintWriter o = new PrintWriter(System.out);

        long k = in.nextInt();
        long b = in.nextInt();
        long n = in.nextInt();
        long t = in.nextInt();

        long z = (long) Math.pow(k, n);
        n--;
        while (n >= 0) {
			z += ( (long) Math.pow(k, n) * b );
			n--;
   		}
		int ans = 0;

        while (t < z) {
			t = (t * k) + b;
			ans++;
		}

        o.println(ans);

        o.close();
        o.flush();
        return;
    }

    static final Random random=new Random();

    static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
  private static BufferedReader br;
  private static StringTokenizer st;
  private static PrintWriter pw;

  public static void main(String[] args) throws IOException {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    //int qq = 1;
    int qq = Integer.MAX_VALUE;
    //int qq = readInt();
    outer: for(int casenum = 1; casenum <= qq; casenum++)  {
      int k = readInt();
      int b = readInt();
      int n = readInt();
      int t = readInt();
      if(t == 1) {
        pw.println(n);
        exitImmediately();
      }
      long curr = 1;
      for(int ans = n; ans >= 0; ans--) {
        curr *= k;
        curr += b;
        if(curr >= t) {
          pw.println(ans);
          continue outer;
        }
      }
      pw.println(0);
    }
    pw.close();
  }

  public static boolean allTrue(boolean[] list) {
    for(boolean out: list) {
      if(!out) {
        return false;
      }
    }
    return true;
  }

  private static void exitImmediately() {
    pw.close();
    System.exit(0);
  }

  private static long readLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  private static double readDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  private static int readInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  private static String nextToken() throws IOException  {
    while(st == null || !st.hasMoreTokens())  {
      if(!br.ready()) {
        exitImmediately();
      }
      st = new StringTokenizer(br.readLine().trim());
    }
    return st.nextToken();
  }
}

import java.util.Scanner;

public class AboutBacteria{

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {

            long k = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();
            long t = in.nextLong();

            long z = 1;
            long secs = 0;

            while(z < t){
                z= z*k + b;
                secs++;
            }

            if(z>t)
                secs--;

            long result = n-secs;

            System.out.println(result);
        }
        in.close();
    }

}

import java.util.Scanner;

public class CF125D2C {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        int t = sc.nextInt();
        int p = k + b;
        int counter = 0;
        while (p <= t&&counter<n) {
                    counter++;
                    p = k * p + b;
        }
        System.out.println(n - counter);
    }

}

import java.util.Scanner;
public class AboutBacteria {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int b = in.nextInt();
        int n = in.nextInt();
        long t = in.nextInt();
        long x = 1;
        long z = 0;
        for(int i = 0; i < n ; i++)
        {
            System.out.println("sec = " + (i+1));
            z = k*x+b;
            System.out.println("z = " + z);
            x = z;
        }
        System.out.println("k = " + k);
        System.out.println("b = " + b);
        System.out.println("n = " + n);
        System.out.println("t = " + t);
        int numOfSeconds = 0;
        while (t < z)
        {
            numOfSeconds++;
            t = k*t+b;
        }
        System.out.println(numOfSeconds);
    }
}

import java.util.Scanner;
import java.math.*;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int k = sc.nextInt();
			int b = sc.nextInt();
			int n = sc.nextInt();
			int t = sc.nextInt();
			int num = 1;
			int years = 0;
			boolean change = false;
			while(num<t&&years<=n){
				num= num*k + b;
				years++;
				change = true;
			}
			if(change){years--;}

			System.out.println(n-years);

		}
	}

}

import java.util.Scanner;

public class AboutBacteria {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        int k = read.nextInt();
        int b = read.nextInt();
        int n = read.nextInt();
        int t = read.nextInt();
        int current = 1;
        int sec = 0;
        while (current < t) {
            current = k * current + b;
            sec++;
            System.out.println(current);
        }
        if (n + 1 - sec < 0)
            System.out.println(0);
        else
            System.out.println(n + 1 - sec);
    }
}

import java.io.*;
import java.util.*;

public class Microbes {

	final String filename = new String("Microbes").toLowerCase();

	void solve() throws Exception {
		long k = nextLong();
		long b = nextLong();
		long n = nextLong();
		long t = nextLong();
		long cur = 1;
		long max = n;
		for (int ans = 0; ; ans++) {
			if (t >= cur) {
				max = n - ans;
			} else {
				break;
			}
			cur = cur * k + b;
		}
		out.println(max);
	}

	void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			//			in = new BufferedReader(new FileReader("input.txt"));
			//			out = new PrintWriter("output.txt");

			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	String nextToken() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws Exception {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws Exception {
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) {
		new Microbes().run();
	}

}

import java.util.Scanner;
import java.math.*;
import java.util.*;

public class JavaAcm
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int i , k , b , n , t , sum = 1;
		k = scan.nextInt();
		b = scan.nextInt();
		n = scan.nextInt();
		t = scan.nextInt();
		i = n;
		while(sum <= t)
		{
			i --;
			sum *= 3;
		}
		i ++;
		if(i < 0)
	       i = 0;
		System.out.println(i);
	}
}

import java.util.Scanner;

public class cf_199C {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int t = sc.nextInt();
		sc.close();
		int x = 1, time = 0;
		if(t == 1) {
			System.out.println(n);
			return;
		}
		else if(t == 0) {
			System.out.println(n + 1);
			return;
		}
		for(time = 0; x <= t; time++)
			x = k*x + b;
		if(time >= n)
			time = 0;
		else time = n - (time - 1);
		System.out.println(time);
	}

}

import java.util.Scanner;

public class cf_199C {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int t = sc.nextInt();
		sc.close();
		int x = 1, time = 0;
		if(t == 1) {
			System.out.println(n);
			return;
		}
		else if(t == 0) {
			System.out.println(n + 1);
			return;
		}
		for(time = 0; x < t; time++)
			x = k*x + b;
		if(time > n)
			time = 0;
		else if(time == n)
			time = 1;
		else if(x == t)
			time = n - time;
		else
			time = n - (time - 1);
		System.out.println(time);
	}

}

import java.util.Scanner;

public class Microbs implements Runnable {
  public void run() {
    try {
      Scanner in = new Scanner(System.in);
      //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int k = in.nextInt();
      int b = in.nextInt();
      int n = in.nextInt();
      int t = in.nextInt();
      int num = 1;
      int s = 0;
      while (num < t) {
        num = k * num + b;
        s++;
      }
      System.out.println(Math.max(n - s + 1, 0));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public static void main(String[] args) {
    new Thread(new Microbs()).start();
  }
}

import java.util.Scanner;

public class MainClass {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Scanner scan = new Scanner(System.in);

        int k = scan.nextInt();
        int b = scan.nextInt();
        int n = scan.nextInt();
        int t = scan.nextInt();
        int req = 1;

        for(int i = 0; i < n ; i++){

            req = (req*k)+b;

        }

        for (int i = 1, req2 =t; true ; i++){

            req2 = (req2*k)+b;
            if(req2 >= req){
                System.out.println(i);
                return;
            }
        }

    }

}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
//      // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        int k=in.nextInt();
        int b=in.nextInt();
        int n=in.nextInt();
        int t=in.nextInt();
        long r=k+b;
        int time=0;
        while(r<t){
            r=(k*r)+b;
            time++;
        }
        if(n-time<0){
        System.out.println("0");
        }
        else{
            System.out.println(n-time);
        }
//
    }
//
}

import java.util.Scanner;
public class Bacteria{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        int b=sc.nextInt();
        int n=sc.nextInt();
        int t=sc.nextInt();
        int z=1;
        int T=0;
        for(int i=0;i<n;i++){
            z=k*z+b;
        }
        int x=t;
        while(z>=x){
            x=k*x+b;
            if(x!=z){
            T++;
            }
        }
        System.out.println(T);

    }

}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CFRound125_Div1_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new CFRound125_Div1_A(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	// solution

	void solve() throws IOException {
		long k = readLong();
		long b = readLong();
		long n = readLong();
		long t = readLong();

		if (t == 1) {
			out.println(n);
			return;
		}

		if (k == 1) {
			long z = 1 + n * b;
			long ans = 0;
			long cnt = t;
			while (true) {
				if (cnt >= z) {
					break;
				}
				cnt += b;
				ans++;
			}
			out.println(ans);
			return;
		}

		for (long x = 0; true; x++) {
			if (log(t) >= (n - x) * log(k) - 1e-12) {
				out.println(x);
				return;
			}
		}
	}

}

import java.util.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException{
Scanner sc = new Scanner(System.in);
int k = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
int t = sc.nextInt();

long count = 1;
for (int i=0; i<n; i++){
  count*=k;
  count+=b;
  if (count>=t){System.out.println(n-i); System.exit(0);}
}
System.out.println(0);

}
}

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	static Scanner scan = new Scanner (System.in);
	static PrintStream out = System.out;
	static long k, b, n, t;

	static long check_nt (long X, long Y, long Z) {
		if (Y > X)
			return 0;
		long ans = 0, tmp = Y;
		System.out.println (X + " " + Y + " " + Z);
		while (tmp < X) {
			tmp *= Z;
			++ans;
		}
		return (tmp > X)?(ans-1):ans;
	}

	static void go () {
		long nt = 0;
		if (k == 1) {
			nt = (t-1)/b;
			System.out.println (Math.max(0, n-nt));
			return;
		}
		long X = (k-1)*t+b, Y = k+b-1, Z = k;
		nt = check_nt (X, Y, Z);
		System.out.println (Math.max (0, n - nt));

	}

	public static void main (String[] args) {
		k = scan.nextLong();
		b = scan.nextLong();
		n = scan.nextLong();
		t = scan.nextLong();

		go ();
	}

}

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();
		if (k != 1) {
			double temp = Math.ceil(Math.pow(k, n)
					/ ((t * (k - 1.0) + b) / (k + b - 1.0)));
			long val = (long) Math.ceil(Math.log(temp) / Math.log(k));
			System.out.println(val);
		} else {
			double res = (1.0 + (b * n-1) - t) / b;
			long val = (long) Math.ceil(res);
			System.out.println(val);
		}
	}
}

import java.util.Scanner;

public class AboutBacteria {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int b = in.nextInt();
        int n = in.nextInt();
        int t = in.nextInt();
        if(k!=1){
            double temp=(t*(k-1.0)+b)/(k+b-1.0);
            temp=Math.pow(k, n)/temp;
            int count=0;
            while(true){
                double v=Math.pow(k, count);
                if(v>=temp){
                    break;
                }
                count++;
            }
            System.out.println(count);
        }
        else{
            double temp=b*n-t+1;
            long val=(long)Math.ceil(temp/b);
            System.out.println(val);
        }
    }
}

import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;

public class Microb implements Runnable {

    final static String taskname = "filename";

    public void solve() throws Exception {

    	String input[] = in.readLine().split(" +");
    	long k = Integer.parseInt(input[0]);
    	long b = Integer.parseInt(input[1]);
    	long n = Integer.parseInt(input[2]);
    	long t = Integer.parseInt(input[3]);

    /*	BigInteger z = BigInteger.ONE;
    	  for ( int i=0 ; i < n; i++){
    		  z = z.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    	  }
    	BigInteger cur = BigInteger.valueOf(t);
    	int  res = 0;
    	  while ( cur.compareTo(z) <= 0) {
    		  cur = cur.multiply(BigInteger.valueOf(k)).add(BigInteger.valueOf(b));
    		  res++;
    	  }   */
    	double delta = 0;
    	if (k==1){

    		delta = Math.floor((t-1)/b);

    	}

    	if ( k > 1) {
    		long up = b*k+(k-1)*t;
    		long down = k-1+b;

    		delta =  (double) up/(double)down;

    	//delta = (b*k+(k-1)*t)/(k-1+b);

    	delta = Math.log(delta)/Math.log(k);

    	delta = (Math.floor(delta)== delta) ? (delta -1) : Math.floor(delta);
    	}

    	int res = (int) (n - delta);

    	 if ( res < 0 ) res =0;

    	out.write(res+"\n");

    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
//             in = new BufferedReader(new FileReader(taskname + ".in"));
//             out = new BufferedWriter(new FileWriter(taskname + ".out"));
            solve();
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public int iread() throws Exception {
        return Integer.parseInt(readword());
    }

    public double dread() throws Exception {
        return Double.parseDouble(readword());
    }

    public long lread() throws Exception {
        return Long.parseLong(readword());
    }

    BufferedReader in;

    BufferedWriter out;

    public String readword() throws IOException {
        StringBuilder b = new StringBuilder();
        int c;
        c = in.read();
        while (c >= 0 && c <= ' ')
            c = in.read();
        if (c < 0)
            return "";
        while (c > ' ') {
            b.append((char) c);
            c = in.read();
        }
        return b.toString();
    }

    public static void main(String[] args) {
        // Locale.setDefault(Locale.US);
        new Thread(new Microb()).start();
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

 public class Main {
    static int arr[], N, K;
    static boolean adj[][];
    static BigInteger dp[][];
    static boolean reach[][];
    static  String str1 [];
     static String str2 [];
     public static void main(String[] args) throws IOException {
         Scanner sc = new Scanner(System.in);
         double k = sc.nextDouble();
         double b = sc.nextDouble();
         double n = sc.nextDouble();
         double t = sc.nextDouble();
         if(k==1){
             double z = b*n;
             n = Math.ceil((z-t)/b);
             System.out.println((n<=0) ? "0" : (long) n);
         }else{
             double z = Math.pow(k,n) + b * ((1 - Math.pow(k,n))/(1-k));
             n = Math.log((z*(1-k)-b) / ((1-k)*t - 1)) / Math.log(k);
             System.out.println((n<=0) ? "0" : (long) Math.ceil(n));
         }
     }

     static class Point
     {
         int x;
         int y;

         public Point(int x, int y)
         {
             this.x = x;
             this.y = y;
         }

     };

     // Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
     static boolean onSegment(Point p, Point q, Point r)
     {
         if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&
                 q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))
             return true;

         return false;
     }

     // To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
     static int orientation(Point p, Point q, Point r)
     {
         // See https://www.geeksforgeeks.org/orientation-3-ordered-points/
         // for details of below formula.
         int val = (q.y - p.y) * (r.x - q.x) -
                 (q.x - p.x) * (r.y - q.y);

         if (val == 0) return 0; // colinear

         return (val > 0)? 1: 2; // clock or counterclock wise
     }

     // The main function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
     static boolean doIntersect(Point p1, Point q1, Point p2, Point q2)
     {
         // Find the four orientations needed for general and
         // special cases
         int o1 = orientation(p1, q1, p2);
         int o2 = orientation(p1, q1, q2);
         int o3 = orientation(p2, q2, p1);
         int o4 = orientation(p2, q2, q1);

         // General case
         if (o1 != o2 && o3 != o4)
             return true;

         // Special Cases
         // p1, q1 and p2 are colinear and p2 lies on segment p1q1
         if (o1 == 0 && onSegment(p1, p2, q1)) return true;

         // p1, q1 and q2 are colinear and q2 lies on segment p1q1
         if (o2 == 0 && onSegment(p1, q2, q1)) return true;

         // p2, q2 and p1 are colinear and p1 lies on segment p2q2
         if (o3 == 0 && onSegment(p2, p1, q2)) return true;

         // p2, q2 and q1 are colinear and q1 lies on segment p2q2
         if (o4 == 0 && onSegment(p2, q1, q2)) return true;

         return false; // Doesn't fall in any of the above cases
     }
/*
     static class Scanner
     {
         StringTokenizer st;
         BufferedReader br;

         public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
         public Scanner(String s) throws FileNotFoundException {
             br = new BufferedReader(new FileReader(s));
         }
         public String next() throws IOException
         {
             while (st == null || !st.hasMoreTokens())
                 st = new StringTokenizer(br.readLine());
             return st.nextToken();
         }

         public int nextInt() throws IOException {return Integer.parseInt(next());}

         public String nextLine() throws IOException {return br.readLine();}

         public long nextLong() throws IOException {return Long.parseLong(next());}

         public boolean ready() throws IOException {return br.ready();}
     }

 */
 }

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z, exp;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double)(z-t) / b);
		} else {
			exp = (long) Math.pow((double) k, (double) n);
			z = exp + (exp - 1) * b / (k - 1);
			n = (long) Math.ceil(Math.log((z*(k-1)+b)/((k-1)*t+b)) / Math.log(k));
		}

		if(t > z) {
			n = 0;
		}

		System.out.println(n);
	}

}

import java.util.Scanner;
public class AboutBacteria {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int k = in.nextInt();
        int b = in.nextInt();
        int n = in.nextInt();
        int t = in.nextInt();
        int x = 1;
        int z = 0;
        for(int i = 0; i < n ; i++)
        {
            z = k*x+b;
            x = z;
        }
        int numOfSeconds = 0;
        while (t < z)
        {
            numOfSeconds++;
            t = k*t+b;
        }
        System.out.println(numOfSeconds);
    }
}

//package CodeForces;

import java.util.Scanner;

public class AboutBacteria {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int k=s.nextInt();int b=s.nextInt();int n=s.nextInt();int t=s.nextInt();
		if(k==1)
		{
			double ans=Math.ceil(((1+n*b-t)*(1.0))/((b)*1.0));
			System.out.println((int)ans);
		}
		else
		{
			double ans=(((t*(k-1)+b)*(1.0))/((k-1+b)*(1.0)));
			for(int i=0;;)
			{
				if(Math.pow(k,n-i)>ans)
				{
					i++;
				}
				else
				{
					System.out.println(i);
					break;
				}
			}
		}

	}

}

import java.util.Scanner;
public class Bacteria{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long k=sc.nextLong();
        long b=sc.nextLong();
        long n=sc.nextLong();
        long t=sc.nextLong();
        long z=1;
        long T=0;
        if(t==1){
            System.out.println(n);
        }else{
            while(z<t){
                z =z *k+b;
                T++;
            }
            T--;
            if(T<n){
            System.out.println(n-T);
            }else{
                System.out.println(0);
            }
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author jesus_000
 */
public class Bacteria {

    public static void main(String[] args) throws IOException {
        InputStreamReader sr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(sr);
        String linea = br.readLine();
        String[] datos = linea.split("\\s");

        int k = Integer.parseInt(datos[0]);
        int b = Integer.parseInt(datos[1]);
        int n = Integer.parseInt(datos[2]);
        int t = Integer.parseInt(datos[3]);
        int x = 1;

        for (int i = 0; i < n; i++) {
            x = k * x + b;
            if (x > t) {
                System.out.println(n - i);
                break;
            } else {
                System.out.println(0);
                break;
            }
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class AboutBacteria_125 {

	public static void main(String[] args) throws IOException {
		// ----------------------------------------------------
		start();
		// ----------------------------------------------------
		int k = nextInt();
		int b = nextInt();
		int n = nextInt();
		int t = nextInt();

		int x = 1;
		for (int i = 0; i < n; i++) {
			x = k * x + b;
		}
		if (t >= x) {
			out.println(0);
		} else {
			int s = 0;
			while (true) {
				t = k * t + b;
				s++;
				if (t >= x) {
					out.println(s);
					break;
				}
			}
		}
		// ----------------------------------------------------
		end();
		// ----------------------------------------------------
	}

	static BufferedReader br;
	static PrintWriter out;
	static StringTokenizer sc;

	static void start() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		sc = new StringTokenizer("");
	}

	static void end() throws IOException {
		br.close();
		out.close();
	}

	static String nextString() throws IOException {
		while (!sc.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			sc = new StringTokenizer(s.trim());
		}
		return sc.nextToken();
	}

	static String nextLine() throws IOException {
		String s = br.readLine();
		if (s == null) {
			return null;
		}
		return s;
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(nextString());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextString());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextString());
	}

	BigInteger nextBigInteger() throws IOException {
		return new BigInteger(nextString());
	}

	static int[] nextIntArray(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	static long[] nextLongArray(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}

	static char[] nextCharArray() throws IOException {
		return nextString().toCharArray();
	}

	static String[] nextStringArray(int n) throws IOException {
		String[] a = new String[n];
		for (int i = 0; i < n; i++)
			a[i] = nextString();
		return a;
	}

}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z, exp;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double) (z-t) / b); // Minimum number of WHOLE seconds
		} else {
			// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
			n = (long) Math.ceil(n+Math.round((Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.log(k)));
		}

		if(n < 0) { // Already have more than enough bacteria
			n = 0;
		}

		System.out.println(n);
	}

}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z=0, exp;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double) (z-t) / b); // Minimum number of WHOLE seconds
		} else {
			if(n*Math.log(k) < 63*Math.log(2)) {
				exp = (long) Math.pow(k, n);
				if(t >= z) {
					n = 0;
				}
			} else {
				// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
				n += (Math.ceil(Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.ceil(Math.log(k)));
			}
		}

		if(n < 0) { // Already have more than enough bacteria
			n = 0;
		}

		System.out.println(n);
	}

}

import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
    Scanner in=new Scanner(System.in);
    int k=in.nextInt();
    int b=in.nextInt();
    int n=in.nextInt();
    long t=in.nextInt();
    long x=1;
    while(n--!=0){
        x=x*k+b;
    }
    int ans=0;
    while(t<x){
        t=t*k+b;
        ans++;
    }
    System.out.println(ans);
//  double H;
//  double U;
//  double D;
//  double F;
//  while(true){
//       H=in.nextDouble();
//       U=in.nextDouble();
//       D=in.nextDouble();
//       F=in.nextDouble();
//       if(H==0){
//          break;
//      }
//      double height=0;
//      double distance_climbed=U;
//      double height_after_climb=U;
//      double height_after_slide=U-D;
//      int i;
//      for(i=1;;i++){
//          height=height_after_slide;
//          U=U-U*(F/100);
//          U=((double)(Math.round(U*10)))/10.0;
//          distance_climbed=U;
//            height_after_climb=height+distance_climbed;
//            height_after_climb=((double)(Math.round(height_after_climb*10)))/10.0;
//            height_after_slide=height_after_climb-D;
//            height_after_slide=((double)(Math.round(height_after_slide*10)))/10.0;
//            if(height_after_climb>H){
//              System.out.println("success on day "+i);
//              break;
//            }
//            if(height_after_slide<0){
//              System.out.println("failure on day "+i);
//              break;
//          }
//      }
//
//    }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AboutBacteria {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        StringTokenizer st = new StringTokenizer(s);

        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        int x = 1;
        int second = 0;

        while(x <= t){
            x = k * x + b;
            second++;
        }
        int soluthion = n - second + 1;
        System.out.println( soluthion>0 ? soluthion : 0 );
    }
}

import java.util.Scanner;

public class Microbs implements Runnable {
  public void run() {
    try {
      Scanner in = new Scanner(System.in);
      //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int k = in.nextInt();
      int b = in.nextInt();
      int n = in.nextInt();
      int t = in.nextInt();
      int num = 1;
      int s = 0;
      while (num <= t) {
        num = k * num + b;
        s++;
      }
      System.out.println(Math.max(n - s + 1, 0));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public static void main(String[] args) {
    new Thread(new Microbs()).start();
  }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        while(input.hasNextInt()){

            int k = input.nextInt();
            int b = input.nextInt();
            int n = input.nextInt();
            int t = input.nextInt();

            long x = 1;
            long z = 1;

            for(int i = 0 ;i < n ;i++){
                x = k*x + b;
            }
            //z = k*x + b;
            z = x;
            //System.out.println("Z = " + z);
            int print = 0;
            if(t >= z){
                System.out.println(print);
            }else{
                long newX = t;
                while(newX <= z ){
                    newX = k*newX + b;
                    //System.out.println("newX = " + newX);
                    print++;
                    //System.out.println("MARA");

                }

                System.out.println(print);

            }

        }//end while

    }//end main

}//end class

import java.util.Scanner;

public class con_1 {

    public static void main(String[] args)  {
        Scanner sc=new Scanner(System.in);
        long k=sc.nextLong();
        long b=sc.nextLong();
        long n=sc.nextLong();
        long t=sc.nextLong();

        long z=1;

        for(int i=0;i<n;i++)
            z=k*z+b;

        int s=0;
        while(t<z){
            t=k*t+b;
            s++;
        }
        System.out.println(s);
    }
}

import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        long k=in.nextLong();
        long b=in.nextLong();
        long n=in.nextLong();
        long t=in.nextLong();
        long z=0;
        z=k+b;
        while(n>0){
            z=(k*z)+b;
            n--;
        }
        t=t+1;
        t=(k*t)+b;
        boolean found =true;
        long time=0;
        while(found==true&&t<z){
            time++;
            t=(k*t)+b;
            if(t>=z){
                found=false;
            }
        }
        System.out.println(time);

    }

}

import java.util.Scanner;
import java.math.*;
import java.util.*;

public class JavaAcm
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int i , k , b , n , t , sum = 1;
		k = scan.nextInt();
		b = scan.nextInt();
		n = scan.nextInt();
		t = scan.nextInt();
		i = n;
		while(sum <= t)
		{
			i --;
			sum *= 3;
		}
		if(i < 0)
	       i = 0;
		System.out.println(i);
	}
}

import java.util.Scanner;

public class cf_199C {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int b = sc.nextInt();
		int n = sc.nextInt();
		int t = sc.nextInt();
		sc.close();
		int x = 1, time = 0;
		if(t == 1) {
			System.out.println(n);
			return;
		}
		else if(t == 0) {
			System.out.println(n + 1);
			return;
		}
		for(time = 0; x <= t; time++)
			x = k*x + b;
		if(time >= n)
			time = 0;
		else time = n - (time - 1);
		System.out.println(time);
	}

}

import java.util.*;
public class AboutBacteria {

    public static void main(String[] args) {
Scanner in = new Scanner (System.in);

int k= in.nextInt();
int b=in.nextInt();
int n=in.nextInt();
long t= in.nextInt();
long z=1;

        for(int i=0;i<n;i++){

        z=z*k+b;

        }
        //System.out.println(z);

        int noOfSec=0;

            while(true){
                if(t>=z)
                    break;

                    t=k*t+b;
                    noOfSec++;
        }

        System.out.println(noOfSec);

    }

}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double)(z-t) / b);
		} else {
			//System.out.println((Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.log(k));
			// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
			n += (long) ((Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.log(k) + 0.1);
		}

		if(n < 0) {
			n = 0;
		}

		System.out.println(n);
	}

}

import java.util.Scanner;
public class Bacteria{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        int b=sc.nextInt();
        int n=sc.nextInt();
        int t=sc.nextInt();
        int z=1;
        int T=0;
        for(int i=0;i<n;i++){
            z=k*z+b;
        }
        int x=t;
        while(z>=x){
            x=k*x+b;
            if(x!=z){
            T++;
            }
        }
        System.out.println(T);

    }

}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class PracticeProblem
{
    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        solve();
        out.close();
    }

    private static  long power(long a, long b)
    {
        long result = 1;
        for (; b > 0; a *= a, b >>= 1)
            if ((b & 1) != 0)
                result *= a;
        return result;
    }

    private static void solve()
    {
        long k = in.nextInt(), b = in.nextInt(), n = in.nextInt(), t = in.nextInt();

        if (k == 1)
        {
            long answer = (n * b - t + 1) / b;
            if ((n * b - t + 1) % b != 0)
                answer++;

            out.println(answer);
            return;
        }

        long max = (t * k - t + b) / (k + b - 1);
        if ((t * k - t + b) % (k + b - 1) != 0)
            max++;

        for (long x = n; x >= 0; x--)
        {
            if (max < power(k, n - x))
            {
                out.println(x + 1);
                return;
            }
        }
        out.println(0);
    }

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.FileWriter;
//import java.lang.StringBuilder;
import java.util.StringTokenizer;
//import java.lang.Comparable;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.ArrayList;
//import java.util.LinkedList;

public class AboutBacteria {

    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(System.out);
    //static StringBuilder sb = new StringBuilder();

    public static void main(String[] args) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        //BufferedReader in = new BufferedReader(new FileReader("input.txt"));
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        int k = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int t = Integer.parseInt(st.nextToken());
        long x = 1;
        int j = 0;
        for(int i = 0; i < n; i++) {
            x = (k * x) + b;
            if(x > t) {
                j++;
            }
        }
        out.print(j);
        out.close();
    }
}

import java.util.Scanner;

public class B {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scr = new Scanner(System.in);
		int k = scr.nextInt();
		int b = scr.nextInt();
		int n = scr.nextInt();
		int t = scr.nextInt();

		int p = 1;
		int kp = k;

		int sum = b;
		while (((sum + kp) < t) && (p <= n)){
			sum = sum + kp*b;
			kp = kp*k;
			p++;
		}
		int m = n - (p-1);

		System.out.println(m);

	}

}

import java.io.*;
import java.util.*;
import java.util.regex.*;

public class Main {
	static Scanner scan = new Scanner (System.in);
	static PrintStream out = System.out;
	static long k, b, n, t;

	static void go () {
		long nt = 0;
		if (k == 1) {
			nt = (t-1)/b;
			System.out.println (Math.max(0, n-nt));
			return;
		}
		nt = (int)Math.floor((Math.log((k-1)*t+b) - Math.log(k+b-1))/Math.log(k));
		System.out.println (Math.max (0, n - nt));

	}

	public static void main (String[] args) {
		k = scan.nextLong();
		b = scan.nextLong();
		n = scan.nextLong();
		t = scan.nextLong();

		go ();
	}

}

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;

@SuppressWarnings("unchecked")
public class Main {

    int mod = 1000000007;

    public class SegmentTree{

       int n;
       int[] tree;

       SegmentTree(int[] arr){

          this.n = arr.length;
          this.tree = new int[2 * n];

          for(int i = n; i < 2 * n; i++){
              this.tree[i] = arr[i - n];
          }

          for(int i = n - 1; i >= 1; i--){
              this.tree[i] = Math.min(this.tree[2 * i], this.tree[2 * i + 1]);
          }

       }

       public boolean isIn(int a){

          a += n;
          return tree[a] >= 1000000;

       }

       public int query(int l, int r){

          int res = Integer.MAX_VALUE;
          l = l + n;
          r = r + n;

          while(l < r){

              if(l % 2 == 1){
                  res = Math.min(res, tree[l]);
                  l++;
              }

              if(r % 2 == 1){
                  r--;
                  res = Math.min(res, tree[r]);
              }

              l /= 2;
              r /= 2;
          }

          return res;
       }

       public void update(int idx, int v){

          idx += n; this.tree[idx] += v;
          while(idx > 1){
             idx /= 2;
             this.tree[idx] = Math.min(this.tree[2 * idx], this.tree[2 * idx + 1]);
          }
       }

    }

    public void solve() throws IOException{

       long k = in.nextLong();
       long b = in.nextLong();
       long n = in.nextLong();
       long t = in.nextLong();

       long cur = 1;
       long cnt = 0;

       while(cur < t){
          cur = (k * cur + b);
          cnt++;
       }

       out.println(Math.max(0, n - (Math.max(0, cnt - 1))));
    }

    FastScanner in;
    PrintWriter out;

    static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException {
            if (st == null || !st.hasMoreTokens())
                return br.readLine();
            StringBuilder result = new StringBuilder(st.nextToken());
            while (st.hasMoreTokens()) {
                result.append(" ");
                result.append(st.nextToken());
            }
            return result.toString();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

    }

    void run() throws IOException {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException{
        new Main().run();
    }

    public void printArr(int[] arr){
        for(int i = 0; i < arr.length; i++){
            out.print(arr[i] + " ");
        }
        out.println();
    }

    public long gcd(long a, long b){
        if(a == 0) return b;
        return gcd(b % a, a);
    }

    public boolean isPrime(long num){

        if(num == 0 || num == 1){
            return false;
        }

        for(int i = 2; i * i <= num; i++){
            if(num % i == 0){
                return false;
            }
        }

        return true;
    }

    public class Pair<A, B>{
        public A x;
        public B y;

        Pair(A x, B y){
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!x.equals(pair.x)) return false;
            return y.equals(pair.y);
        }

        @Override
        public int hashCode() {
            int result = x.hashCode();
            result = 31 * result + y.hashCode();
            return result;
        }

    }

    class Tuple{
        int x; int y; int z;
        Tuple(int ix, int iy, int iz){
            x = ix;
            y = iy;
            z = iz;
        }
    }
}

import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
            long k = nextLong();
            long b = nextLong();
            long n = nextLong();
            long t = nextLong();

            //try to make the 1st experiment to reach T, -------(1)
            // since you already know time taken to reach Z in 1st experiment-----(2)
            //thus from T we can reach Z, in (2) minus(1);
            long count = 1;
            int time = 0;
            while(count < t){
                count = count * k + b;
                time++;
            }

            long answer = Math.max(0, n - time + 1);
            out.println(answer);
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void debug(Object... arr){
            System.out.println(Arrays.deepToString(arr));
        }

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
			tok = null;
			solve();
			in.close();
                        out.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
        PrintWriter out;
	BufferedReader in;
	StringTokenizer tok;
}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z, exp;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			n = (long) Math.ceil((double)(z-t) / b);
		} else {
			// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
			n += (long) ((Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.log(k));
		}

		if(n < 0)
			n = 0;

		System.out.println(n);
	}

}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        double k = r.nextDouble();
        double b = r.nextDouble();

        double n = r.nextDouble();
        double t = r.nextDouble();

        if(k == 1){
            if(b == 0){
                System.out.println(0);
                return;
            }else{
                double x = (1 + b * n - t) / b;
                System.out.println((int)Math.ceil(x - 1e-7));
                return;
            }
        }

        if(t == 1){
            System.out.println(n);
            return;
        }

        double A = (b + t * k - t) / (k - 1 + b);
//      System.out.println(A);

        double x = n - Math.log(A) / Math.log(k);

//      System.out.println(x);
        System.out.println(Math.max(0, (int)Math.ceil(x - 1e-7)));

    }
}

import java.io.*;
import java.util.*;

public class Contest1_1{

    public static void main(String ar[]) throws Exception {

        BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(buff.readLine());
        long k = Long.parseLong(tok.nextToken());
        long b = Long.parseLong(tok.nextToken());
        long n = Long.parseLong(tok.nextToken());
        long t = Long.parseLong(tok.nextToken());
        long z = 1;
        for(long i =0;i<n;i++){
            z = (k*z) + b;
        }
        int count =0;
        while(t<z){
            t = (k*t) + b;
            count++;
        }

        System.out.println(count);
    }
}

import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author tengxiao
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long k=in.nextLong(),b=in.nextLong(),n=in.nextLong(),t=in.nextLong();
        long m=0;
        long tmpm=0;
        if(k==1){
            tmpm = (1+n*b-t)/b;
            if(tmpm<0)
                m=0;
            else
                m=(long)Math.ceil(tmpm);
        }
        else{
            double tmp=(Math.pow(k,n)*(k+b-1))/(t*k-t+b);
            if(tmp<=1)
                m=0;
            else{
                tmp=logb(tmp,k);
                m=(long)Math.ceil(tmp);
            }
        }
        out.println(m);
	}

    public double logb( double a, double b )
    {
        return Math.log(a) / Math.log(b);
    }
}

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int k = input.nextInt();
        int b = input.nextInt();
        int n = input.nextInt();
        int t = input.nextInt();
        int cur = 1;
        while(cur < t){
            cur = cur*k+b;
            n--;
        }

        if(n > 0){
            System.out.println(n+1);
        }
        else
            System.out.println(0);
    }

}

import java.io.PrintWriter;
import java.util.Scanner;

public class AboutMicrobes {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();
		int t = in.nextInt();
		for (int answer = 0; answer < n + 1; answer++) {
			double gpSum = 0;
			if (k == 1) {
				gpSum = (n - answer) * b;
			} else {
				gpSum = b * (1 - Math.pow(k, n - answer - 1)) / (1 - k);
			}
			double expr = Math.pow(k, n - answer) + gpSum + b;
			if (expr <= t) {
				PrintWriter out = new PrintWriter(System.out);
				out.println(answer);
				out.flush();
				return;
			}
		}
	}

}

import java.util.*;
public class AboutBacteria {

    public static void main(String[] args) {
Scanner in = new Scanner (System.in);

int k= in.nextInt();
int b=in.nextInt();
int n=in.nextInt();
int t= in.nextInt();
int z=1;

        for(int i=0;i<n;i++){

        z=z*k+b;

        }

        int noOfSec=0;

            while(true){
                if(t>=z)
                    break;

                    t=k*t+b;
                    noOfSec++;
        }

        System.out.println(noOfSec);

    }

}

import java.util.*;

public class Bacteria{
	public static int solve(int k, int b, int n, int t){
		if( k == 1 ){
		//	System.out.println(n-(double)(t-1)/b);
		//	System.out.println(Math.ceil(2));
			int x = (int)Math.ceil(n-(double)(t-1)/b);
			return (x < 0) ? 0 : x;
		}

		long key = (-1+k)*t+b;
	//	System.out.println(key);
		long temp = -1+k+b;
		int ans = 0;
		while( temp <= key ){
			temp *= k;
			ans++;
		}
		return (n+1-ans < 0 ) ? 0 : n+1-ans;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int k = stdIn.nextInt();
		int b = stdIn.nextInt();
		int n = stdIn.nextInt();
		int t = stdIn.nextInt();

		System.out.println(solve(k, b, n, t));
	}
}

import java.util.*;
public class Main {

    public static void main(String [] args){
    	     long x=1;  int cnt=0;
    	   Scanner in = new Scanner(System.in);
    	       long k = in.nextLong();
    	            long b = in.nextLong();
    	               long n = in.nextLong();
    	                  long t = in.nextLong();

    	                  while(x<t){

    	                  	x= k*x + b;
    	                  	  cnt++;
    	                  }

    	                  if(x==t)
    	                  	System.out.print((n-cnt));

    	                  	else if(x>t)
    	                  System.out.print((n-cnt+1));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class AboutBacteria {
	public static void main(String[] args) throws Exception {
		BufferedReader k1 = new BufferedReader(new InputStreamReader(System.in));
		String[] s=k1.readLine().split(" ");
		//BigInteger k=new BigInteger(s[0]);
		//BigInteger b=new BigInteger(s[1]);
		long k=Long.parseLong(s[0]);
		long b=Long.parseLong(s[1]);
		long n=Long.parseLong(s[2]);
		long t=Long.parseLong(s[3]);
		long second=0;
		long i=1;
		while(i<t){
			i=i*k+b;
			second++;
		}
		if(n-second<0) {
			System.out.println(0);
		}else
		System.out.println(n-second+1);
//		BigInteger t=new BigInteger(s[3]);
//		BigInteger z=BigInteger.ZERO;
//		while(n-->0){
//			z=z.multiply(k);
//			z=z.add(b);
//		}
//		System.out.println(z);
//		int second=0;
//		while(t.compareTo(z)<0){
//			t=t.multiply(k);
//			t=t.add(b);
//			second++;
//		}
//		System.out.println(second);
	}
}

import java.util.Scanner;
import java.math.*;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int k = sc.nextInt();
			int b = sc.nextInt();
			int n = sc.nextInt();
			int t = sc.nextInt();
			int num = 1;
			int years = 0;
			boolean change = false;
			while(num<=t&&years<=n){
				num= num*k + b;
				years++;
				change = true;
			}
			if(change){years--;}

			System.out.println(n-years);

		}
	}

}

//package contest_125_div2;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
/**
 * Date     : Jul 8, 2012
 * Time     : 1:37:38 PM
 * Email    : denys.astanin@gmail.com
 */

public class C {
	public static void main(String[] args) throws IOException {
		new C().run();
	}

	int nextInt() throws IOException {
		in.nextToken();
		return (int) in.nval;
	}

	String nextString() throws IOException {
		in.nextToken();
		return (String) in.sval;
	}

	StreamTokenizer in;
	Writer writer;
	Reader reader;

	void run() throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		reader = oj ? new InputStreamReader(System.in, "ISO-8859-1")
				: new FileReader("src/contest_125_div2/C.txt");
		writer = new OutputStreamWriter(System.out, "ISO-8859-1");
		in = new StreamTokenizer(new BufferedReader(reader));
		PrintWriter out = new PrintWriter(writer);
		int k = nextInt();
		int b = nextInt();
		int n = nextInt();
		int t = nextInt();

	    long result=0;
	    long time=0;
		while(result <= t && time < n){
	        result = result * k+b;
	        time++;
	    }
	    if(result<=t){
	    	out.println(0);
	    } else {
	    	out.println(n-(time-1));
	    }
		out.flush();
		out.close();
	}
}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        double k = r.nextDouble();
        double b = r.nextDouble();

        double n = r.nextDouble();
        double t = r.nextDouble();

        if(k == 1){
            if(b == 0){
                System.out.println(0);
                return;
            }else{
                double x = (1 + b * n - t) / b;
                System.out.println((int)Math.ceil(x));
                return;
            }
        }

        //try zero;
        double ans = Math.pow(k, n) + b  * (Math.pow(k, n) - 1) / (k - 1);
        if(ans == ans && (Math.abs(t - ans) < 1e-9 || t > ans)){
            System.out.println(0);
            return;
        }

        double A = (b + t * k - t) / (k - 1 + b);
//      System.out.println(A);

        double x = n - Math.log(A) / Math.log(k);

        System.out.println(x);
        System.out.println((int)Math.ceil(x));

    }
}

import java.util.Scanner;
import java.math.*;

public class AboutBacteria {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long t = sc.nextLong();
        long x=1;
        long seconds=0;
        for(long i=0 ; i<=n ; i++){
            if(t>x){
                x=k*x+b;
            }
            else{
                seconds=n-i+1;
                break;
            }

        }
        if(t>1)
            System.out.println(seconds);
        else
            System.out.println(seconds-1);
    }
}

/**
 *
 *

 * Unsolved - math
 *

 *

 * Created on Jun 22, 2012, 11:55:52 AM
 *

 * @Author Andy Y.F. Huang
 */
public class p199CAboutBacteria {
  private Input in;
  private Output out;

  void solve() {
    in = new Input();
    out = new Output();
    solve(1);
    out.print();
  }

  void solve(int test_number) {
    int k = in.nextInt();
    int b = in.nextInt();
    int n = in.nextInt();
    int t = in.nextInt();
    int cur = 1;
    for (int i = n; i >= 1; i--) {
      cur = k * cur + b;
      if (cur > t) {
        out.appendln(i);
        return;
      }
    }
    out.appendln(0);
  }

  public static void main(String[] args) {
    p199CAboutBacteria solver = new p199CAboutBacteria();
    solver.solve();
  }

  static void pln(Object... obj) {
    pf(obj);
    System.out.println();
  }

  static void pf(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        System.out.print(' ');
      System.out.print(obj[i]);

    }
  }
}

final class Input {
  private java.io.BufferedReader reader;
  private java.util.StringTokenizer tokenizer;
  private final String filename;
  private static final String k_default_filename = "input.txt";

  Input() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setIn(new java.io.FileInputStream(filename));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    reader = new java.io.BufferedReader(
        new java.io.InputStreamReader(System.in));
    tokenizer = new java.util.StringTokenizer("");
  }

  Input(String filename) {
    this.filename = filename;
    try {
      reader = new java.io.BufferedReader(new java.io.FileReader(this.filename));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    tokenizer = new java.util.StringTokenizer("");
  }

  String next() {
    while (!tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      }
      catch (java.io.IOException e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  String nextLine() {
    try {
      return reader.readLine();
    }
    catch (java.io.IOException e) {
      throw new RuntimeException(e);
    }
  }

  long nextLong() {
    return Long.parseLong(next());
  }

  int nextInt() {
    return Integer.parseInt(next());
  }

  double nextDouble() {
    return Double.parseDouble(next());
  }

}

final class Output {
  private StringBuilder buffer;
  private final String filename;
  private static final String k_default_filename = "output.txt";

  Output(String filename) {
    this.filename = filename;
    try {
      System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
          this.filename)));
    }
    catch (java.io.FileNotFoundException e) {
      throw new RuntimeException(e);
    }
    buffer = new StringBuilder(1 << 16);
  }

  Output() {
    filename = k_default_filename;
    if (new java.io.File(filename).exists()) {
      try {
        System.setOut(new java.io.PrintStream(new java.io.FileOutputStream(
            filename)));
      }
      catch (java.io.FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    }
    buffer = new StringBuilder(1 << 16);
  }

  void print() {
    System.out.print(buffer.toString());
  }

  void flush() {
    System.out.flush();
  }

  void append(Object... obj) {
    for (int i = 0; i < obj.length; i++) {
      if (i != 0)
        buffer.append(' ');
      buffer.append(obj[i]);
    }
  }

  void appendln(Object... obj) {
    append(obj);
    buffer.append('\n');
  }

}

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Crash
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int k = in.readInt();
		int b = in.readInt();
		int n = in.readInt();
		int t = in.readInt();
		long now = 1;
		int cnt = 0;
		while (now < t) {
			cnt ++;
			now = now * k + b;
		}
		out.printLine(Math.max(0, n - cnt + 1));
	}
}

class InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1000];
	private int curChar;
	private int numChars;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	private int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}
}

// package p198A;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long k, b, n, t, z, x;
		k = sc.nextInt();
		b = sc.nextInt();
		n = sc.nextInt();
		t = sc.nextInt();

		if(k == 1) {
			z = 1 + n*b;
			x = (long) Math.ceil((double)(z-t) / b);
		} else {
			// PHEW! That was daunting! LESSON LEARNT: Avoid large exponents as much as possible!
			x = n + (long) ((Math.log((k-1)+b)-Math.log(t*(k-1)+b)) / Math.log(k));
		}

		if(x < 0) {
			x = 0;
		} else if(x == n && x > 1) {
			x -= 1;
		}

		System.out.println(x);
	}

}

import java.util.*;
import java.io.*;
public class C199 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	static StringTokenizer st;
	public static void main(String[]args)throws IOException {
		int k = readInt(); int b = readInt(); int n = readInt(); int t = readInt();
		int z = 1;
		if(t==1) {
			System.out.println(n);
		}

		else {
			int i = 1;
			for(i = 1; i<=n; i++) {
				z = z*k+b;
				if(z>t)break;
			}
			System.out.println(n-i+1);
		}
	}
	static String next () throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine().trim());
		return st.nextToken();
	}
	static long readLong () throws IOException {
		return Long.parseLong(next());
	}
	static int readInt () throws IOException {
		return Integer.parseInt(next());
	}
	static double readDouble () throws IOException {
		return Double.parseDouble(next());
	}
	static char readCharacter () throws IOException {
		return next().charAt(0);
	}
	static String readLine () throws IOException {
		return br.readLine().trim();
	}
}

import java.util.Scanner;

public class CF199C {
	public static void main(String[] args) {
		Scanner myScan = new Scanner(System.in);
		int k = myScan.nextInt();
		int b = myScan.nextInt();
		int n = myScan.nextInt();
		int t = myScan.nextInt();
		int z = 1;

		for (int i = 0; i < n; i++) {
			z = (k * z + b);
		}

		int sec = 1;
		if ((k * t + b) >= z) {
			System.out.println(0);
		} else {

			while ((k * t + b) < z) {
				sec++;
				t = (k * t + b);
			}
			System.out.println(sec);
		}

	}
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;

public class C
{
	BufferedReader in;
	PrintStream out;
	StringTokenizer tok;
	public C() throws NumberFormatException, IOException
	{
		in = new BufferedReader(new InputStreamReader(System.in));
		//in = new BufferedReader(new FileReader("in.txt"));
		out = System.out;
		run();
	}
	void run() throws NumberFormatException, IOException
	{
		long k = nextInt(),b= nextInt(),n= nextInt(),t= nextInt();
		long z = 1;
		for(long i = 0; i < n; i++)
			z = z*k+b;
		long i = 0;
		for(; t < z; i++)
			t = t*k + b;
		out.println(i);
	}
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		new C();
	}
	String nextToken() throws IOException
	{
		if(tok ==null || !tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
		return tok.nextToken();
	}
	int nextInt() throws NumberFormatException, IOException
	{
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws NumberFormatException, IOException
	{
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws NumberFormatException, IOException
	{
		return Double.parseDouble(nextToken());
	}
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

	public static void main(String[] args) throws IOException
	{
		new Main().execute();
	}

	void debug(Object...os)
	{
		System.out.println(Arrays.deepToString(os));
	}

	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}

	long nl() throws IOException
	{
		return Long.parseLong(ns());
	}

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

	String ns() throws IOException
	{
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(br.readLine());
		return tokenizer.nextToken();
	}

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;
	long k,b,n,a;

	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			if(!input())
				break;
			solve();
		}
	}

	void solve() throws IOException
	{
		long x = ((k-1)*a + b);
		long ans = 0;
		if(k == 1)
		{
			long al = (1 + b*n - a);
			long bl = b;
			ans = al/bl;
			if(al%bl != 0)
				ans++;
		}
		else
		{
			long y = (k-1+b);// * (long)Math.pow(k,n-i);
			//int mul = 0;
			//ans = n;
			//double nm = x/(double)y;
			int count = 0;
			//debug(nm);
			while(x>=y)
			{
				//debug(x,y);
				y = y*k;
				count++;

			}
			ans = n-count;
		}
		System.out.println((long)Math.max(0,ans));

	}
	//void bs(long a, long b)

	boolean input() throws IOException
	{
		k = nl();
		b = nl();
		n = nl();
		a = nl();

		return true;
	}

}

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner r = new Scanner(System.in);

        double k = r.nextDouble();
        double b = r.nextDouble();

        double n = r.nextDouble();
        double t = r.nextDouble();

        if(k == 1){
            double x = (1 + b * n - t) / b;
            System.out.println((int)Math.ceil(x));
            return;
        }

        //try zero;
        double ans = Math.pow(k, n) + b  * (Math.pow(k, n) - 1) / (k - 1);
        if(Math.abs(t - ans) < 1e-9 || t > ans){
            System.out.println(0);
            return;
        }

        double A = (b + t * k - t) / (k - 1 + b);
//      System.out.println(A);

        double x = n - Math.log(A) / Math.log(k);

//      System.out.println(x);
        System.out.println((int)Math.ceil(x));

    }
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class CFRound125_Div1_A implements Runnable {

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public static void main(String[] args) {
		new Thread(null, new CFRound125_Div1_A(), "", 256 * (1L << 20)).start();
	}

	@Override
	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			Locale.setDefault(Locale.US);
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long freeMemory = Runtime.getRuntime().freeMemory();
			long totalMemory = Runtime.getRuntime().totalMemory();
			long endTime = System.currentTimeMillis();
			System.err.println("Time = " + (endTime - startTime));
			System.err.println("Memory = " + ((totalMemory - freeMemory) >> 10));
		} catch (Throwable t) {
			t.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	/** http://pastebin.com/j0xdUjDn */
	static class Utils {

		private Utils() {}

		public static void mergeSort(int[] a) {
			mergeSort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 50;

		private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergeSort(a, leftIndex, middleIndex);
					mergeSort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

	// solution

	void solve() throws IOException {
		long k = readLong();
		long b = readLong();
		long n = readLong();
		long t = readLong();

		if (t == 1) {
			out.println(n);
			return;
		}

		if (k == 1) {
			long z = 1 + n * b;
			long ans = 0;
			long cnt = t;
			while (true) {
				if (cnt >= z) {
					break;
				}
				cnt += b;
				ans++;
			}
			out.println(ans);
			return;
		}

		long left = 0, right = n, ans = 0;
		while (left <= right) {
			long x = (left + right) / 2;
			if (log(t) >= (n - x) * log(k) - 1e-9) {
				ans = x;
				right = x - 1;
			} else {
				left = x + 1;
			}
		}
		out.println(ans);
	}

}

import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author tengxiao
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    private final static double EPSILON = 0.0000000001;

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long k=in.nextLong(),b=in.nextLong(),n=in.nextLong(),t=in.nextLong();
        long m=0;
        if(k==1){
            if((1+n*b-t)%b==0)
                m=(1+n*b-t)/b;
            else
                m=(1+n*b-t)/b+1;
        }
        else{
            double tmp=(Math.pow(k,n)*(k+b-1))/(t*k-t+b);
            if(Math.abs(tmp-1)<EPSILON)
                m=0;
            else{
                tmp=logb(tmp,k);
                long tmpm=(long)tmp;
                if(Math.abs(tmpm-tmp)<EPSILON)
                    m=tmpm;
                else
                    m=(long)Math.ceil(tmp);
            }
        }
        out.println(m);
	}

    public double logb( double a, double b )
    {
        return Math.log(a) / Math.log(b);
    }
}

import java.util.Scanner;

public class AboutBacteria{

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext())
        {

            long k = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();
            long t = in.nextLong();

            long z = 1;
            long secs = 0;

            while(z < t){
                z= z*k + b;
                secs++;
            }

            if(z>t)
                secs--;

            long result = n-secs;

            System.out.println(result);
        }
        in.close();
    }

}

import java.util.Scanner;
import java.math.*;

public class AboutBacteria {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int k = sc.nextInt();
			int b = sc.nextInt();
			int n = sc.nextInt();
			int t = sc.nextInt();
			int num = 1;
			int years = 0;
			boolean change = false;
			while(num<t&&years<=n){
				num= num*k + b;
				years++;
				change = true;
			}
			if(change){years--;}

			System.out.println(n-years);

		}
	}

}

import java.util.Scanner;

public class Microbs implements Runnable {
  public void run() {
    try {
      Scanner in = new Scanner(System.in);
      //BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int k = in.nextInt();
      int b = in.nextInt();
      int n = in.nextInt();
      int t = in.nextInt();
      int num = 1;
      int s = 0;
      while (num < t) {
        num = k * num + b;
        s++;
      }
      System.out.println(Math.max(n - s + 1, 0));
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

  public static void main(String[] args) {
    new Thread(new Microbs()).start();
  }
}