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

public class mars_nv_bigint {

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

	PrintWriter out;
	BufferedReader br;
	StringTokenizer st;

	String nextToken() throws IOException {
		while ((st == null) || (!st.hasMoreTokens()))
			st = new StringTokenizer(br.readLine());
		return st.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());
	}

	
	public void solve() throws IOException {
		long n = nextLong();
		long ans = 0;
		BigInteger k = BigInteger.valueOf(nextLong());
		BigInteger fact = BigInteger.ONE;
		for (long i = 1; i <= n; i++)
		{
			fact = fact.multiply(BigInteger.valueOf(i));
			while (fact.mod(k).equals(BigInteger.ZERO))
			{
				ans++;
				fact = fact.divide(k);
			}
		}
		out.println(ans);
	}

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

			br = new BufferedReader(new FileReader("mars.in"));
			out = new PrintWriter("mars.out");

			solve();

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