import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
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();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long base = in.nextLong();

            List<Long> pf = Numerics.primeFactors(base);
            Map<Long, Integer> pfMap = new HashMap<>();
            for (Long x : pf) {
                pfMap.put(x, pfMap.getOrDefault(x, 0) + 1);
            }

            Long result = Long.MAX_VALUE;
            for (long x : pfMap.keySet()) {
                long count = getCount(x, n);
                result = Math.min(result, count / pfMap.get(x));
            }

            out.println(result);
        }

        long getCount(long x, long n) {
            long result = 0;
            while (n > 0) {
                result += n / x;
                n /= x;
            }
            return result;
        }

    }

    static class Numerics {
        public static List<Long> primeFactors(long n) {
            List<Long> result = new ArrayList<Long>();
            while (n % 2 == 0) {
                result.add(2L);
                n = n / 2;
            }

            for (long i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    result.add(i);
                    n = n / i;
                }
            }

            if (n > 2) result.add(n);
            return result;
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

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

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                    //tok = new StringTokenizer(in.readLine(), ", \t\n\r\f"); //adds commas as delimeter
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}

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 badcw
 */
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 {
        long INF = 0x3f3f3f3f3f3f3f3fL;

        long cal(long n, long b) {
            long res = 0;
            if (n < b) return 0;
            for (long i = b; n / i >= 0; i *= b) {
                res += n / i;
                if (b > n / i) break;
            }
            return res;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            long res = INF;
            for (long i = 2; i * i <= b; ++i) {
                int k = 0;
                while (b % i == 0) {
                    b /= i;
                    k++;
                }
                if (k != 0) {
                    res = Math.min(res, cal(n, i) / k);
                }
            }
            if (b != 1) {
                res = Math.min(res, cal(n, b));
            }
            out.println(res);
        }

    }
}

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 Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.nl(), b = in.nl();
            long[] divs = new long[500];
            int[] divcnt = new int[500];
            int di = 0;
            for (long div = 2; div * div <= b; div++) {
                if (b % div == 0) {
                    divs[di++] = div;
                    while (b % div == 0) {
                        divcnt[di - 1]++;
                        b /= div;
                    }
                }
            }
            if (b > 1) {
                divs[di++] = b;
                divcnt[di - 1] = 1;
            }
            //System.out.println("Arrays.toString(divs) = " + Arrays.toString(divs));
            //System.out.println("Arrays.toString(divcnt) = " + Arrays.toString(divcnt));
            long min = Long.MAX_VALUE;
            for (int i = 0; i < di; i++) {
                long div = divs[i];
                long pow = div;
                long cnt = n / pow;
                while (pow < n && pow <= (n + div - 1) / div) {
                    pow *= div;
                    if (pow < n)
                        cnt += n / pow;
                }
                min = Math.min(min, cnt / divcnt[i]);
            }
            out.println(min);

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

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

    }
}

import java.util.Scanner;

public class TrailingLoves {

	public static void main(String [] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long b = sc.nextLong();
		long i=0, j=0, p=0, c=0, k=0, noz=0;

		noz = n;
		j = b;

		for(i=2;i * i<=b;i++) {
			if(j%i == 0) {

				p=0;
				while(j%i == 0) {
					p++;
					j/=i;
				}
				c=0;
				k=n;
				while(k/i > 0) {
					c+=k/i;
					k/=i;
				}
				noz = Math.min(noz, c/p);
			}
		}

		if(j > 1) {
			i = j;
			p=0;
			while(j%i == 0) {
				p++;
				j/=i;
			}
			c=0;
			k=n;
			while(k/i > 0) {
				c+=k/i;
				k/=i;
			}
			noz = Math.min(noz, c/p);
		}

		System.out.println(noz);

	}

}

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

public class C {
    static MyScanner sc;
    static PrintWriter pw;

    public static void main(String[] args) throws Throwable {
        sc = new MyScanner();
        pw = new PrintWriter(System.out);

        long n = sc.nextLong();
        long b = sc.nextLong();

        sieve((int) 1e6 + 5);
        long ans = Long.MAX_VALUE;
        ArrayList<Long> pf = primeFactors(b);
        int cnt = 0;
        for (int i = 0; i < pf.size(); i++) {
            cnt++;
            if (i == pf.size() - 1 || !pf.get(i + 1).equals(pf.get(i))) {
                long pow = count(n, pf.get(i)) / cnt;
                ans = Math.min(ans, pow);
                cnt = 0;
            }
        }
        pw.println(ans);

        pw.flush();
        pw.close();
    }

    static long count(long n, long p) {
        long ans = 0;
        for (long i = p; i <= n; i *= p) {
            ans += n / i;
            if (i > n / p)
                break;
        }
        return ans;

    }

    static ArrayList<Integer> primes;
    static int[] isComposite;

    static void sieve(int N)    // O(N log log N)
    {
        isComposite = new int[N + 1];
        isComposite[0] = isComposite[1] = 1;            // 0 indicates a prime number
        primes = new ArrayList<Integer>();

        for (int i = 2; i <= N; ++i)                    //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
            if (isComposite[i] == 0)                    //can loop in 2 and odd integers for slightly better performance
            {
                primes.add(i);
                if (1l * i * i <= N)
                    for (int j = i * i; j <= N; j += i)    // j = i * 2 will not affect performance too much, may alter in modified sieve
                        isComposite[j] = 1;
            }
    }

    static ArrayList<Long> primeFactors(long N)        // O(sqrt(N) / ln sqrt(N))
    {
        ArrayList<Long> factors = new ArrayList<Long>();        //take abs(N) in case of -ve integers
        int idx = 0;
        long p = primes.get(idx);

        while (p * p <= N) {
            while (N % p == 0) {
                factors.add(p);
                N /= p;
            }
            p = primes.get(++idx);
        }

        if (N != 1)                        // last prime factor may be > sqrt(N)
            factors.add(N);                // for integers whose largest prime factor has a power of 1
        return factors;
    }

    static void shuffle(int[] a) {
        Random r = new Random();
        for (int i = 0; i < a.length; i++) {
            int x = r.nextInt(a.length);
            int y = r.nextInt(a.length);
            int tmp = a[x];
            a[x] = a[y];
            a[y] = tmp;
        }
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }
    }
}

import java.util.Scanner;

// C soln seen
public class TrailingLoves {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long n=scn.nextLong();
		long b=scn.nextLong();
		long ans=Long.MAX_VALUE;
		//System.out.println(ans+" aaaa");
		for(long i=2;i<=b;i++) {
			if(i*i>b) i=b;
			int count=0;
			while(b%i==0) {
				b/=i;
				count++;
			}
			if(count==0)
				continue;
			long mul=1,y=0;
			while(n/i>=mul) {
				mul*=i;
				//System.out.println(mul);
				y+=n/mul;
			}
			ans=Math.min(ans, y/count);
		}
		System.out.println(ans);
	}

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author madi.sagimbekov
 */
public class C1114C {

    private static BufferedReader in;
    private static BufferedWriter out;

    private static List<Integer>[] list;
    private static int[] arr;
    private static int[][] dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    private static boolean[] used;

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

        long[] a = readLongs();
        long n = a[0];
        long b = a[1];

        long b1 = b;

        List<long[]> divs = new ArrayList<>();

        for (int i = 2; (long)i * (long)i <= b; i++) {
            if (b % i == 0) {
                long cnt = 0;
                while (b % i == 0) {
                    cnt++;
                    b /= i;
                }
                divs.add(new long[]{i, cnt});
            }
        }

        if (b > 1) {
            divs.add(new long[]{b, 1});
        }

        //for (long[] t : divs) {
        //    System.out.println(t[0] + " " + t[1]);
        //}

        //Collections.sort(divs, (A,B) -> (B[0] > A[0] ? 1 : (B[0] == A[0] ? (B[1] > A[1] ? 1 : -1) : -1)));

        long result = Long.MAX_VALUE;

        for (int i = 0; i < divs.size(); i++) {

            long[] max = divs.get(i);
            long maxDiv = max[0];
            long maxCnt = max[1];

            long ans = 0;
            long temp = n;
            while (temp > 0) {
                ans += temp / maxDiv;
                temp /= maxDiv;
            }

            ans /= maxCnt;

            if (ans < result) {
                result = ans;
            }

        }

        out.write((result == Long.MAX_VALUE ? 0 : result) + "\n");

        close();
    }

    private static int[] readInts() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }

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

    private static long[] readLongs() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
    }

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

    private static double[] readDoubles() throws IOException {
        return Stream.of(in.readLine().split(" ")).mapToDouble(Double::parseDouble).toArray();
    }

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

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

    private static List<Integer>[] buildAdjacencyList(int n, int m) throws IOException {
        List<Integer>[] list = new ArrayList[n + 1];
        for (int i = 0; i <= n; i++) {
            list[i] = new ArrayList<>();
        }

        for (int i = 0; i < m; i++) {
            int[] e = readInts();
            list[e[0]].add(e[1]);
            list[e[1]].add(e[0]);
        }

        return list;
    }

    private static void open() {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new BufferedWriter(new OutputStreamWriter((System.out)));
    }

    private static void close() throws IOException {
        out.flush();
        out.close();
        in.close();
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
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;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            long ans = Long.MAX_VALUE;
            if (NT.isPrime(b)) {
                ans = Math.min(ans, getAns(n, b));
            } else {
                int[] primes = NT.sieveEratosthenes(2000_000_0);
                for (int p : primes) {
                    if (b % p != 0 || b < p) continue;
                    int ct = 0;
                    while (b % p == 0) {
                        ++ct;
                        b /= p;
                    }
                    ans = Math.min(ans, getAns(n, p) / ct);
                }
                if (b != 1) {
                    ans = Math.min(ans, getAns(n, b));
                }
            }
            out.println(ans);
        }

        private long getAns(long n, long p) {
            long temp = 0;
            while (n / p > 0) {
                temp += n / p;
                n /= p;
            }
            return temp;
        }

    }

    static class NT {
        public static boolean isPrime(long number) {
            if (number <= 1) {
                return false;
            }
            if (number <= 3) {
                return true;
            }
            if (number % 2 == 0 || number % 3 == 0) {
                return false;
            }
            long i = 5;
            while (i * i <= number) {
                if (number % i == 0 || number % (i + 2) == 0) {
                    return false;
                }
                i += 6;
            }
            return true;
        }

        public static int[] sieveEratosthenes(int n) {
            if (n <= 32) {
                int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
                for (int i = 0; i < primes.length; i++) {
                    if (n < primes[i]) {
                        return Arrays.copyOf(primes, i);
                    }
                }
                return primes;
            }

            int u = n + 32;
            double lu = Math.log(u);
            int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
            ret[0] = 2;
            int pos = 1;

            int[] isnp = new int[(n + 1) / 32 / 2 + 1];
            int sup = (n + 1) / 32 / 2 + 1;

            int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31};
            for (int tp : tprimes) {
                ret[pos++] = tp;
                int[] ptn = new int[tp];
                for (int i = (tp - 3) / 2; i < tp << 5; i += tp)
                    ptn[i >> 5] |= 1 << (i & 31);
                for (int j = 0; j < sup; j += tp) {
                    for (int i = 0; i < tp && i + j < sup; i++) {
                        isnp[j + i] |= ptn[i];
                    }
                }
            }

            // 3,5,7
            // 2x+3=n
            int[] magic = {0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,
                    9, 6, 16, 5, 15, 14};
            int h = n / 2;
            for (int i = 0; i < sup; i++) {
                for (int j = ~isnp[i]; j != 0; j &= j - 1) {
                    int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
                    int p = 2 * pp + 3;
                    if (p > n)
                        break;
                    ret[pos++] = p;
                    if ((long) p * p > n)
                        continue;
                    for (int q = (p * p - 3) / 2; q <= h; q += p)
                        isnp[q >> 5] |= 1 << q;
                }
            }

            return Arrays.copyOf(ret, pos);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

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

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

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

    }
}

import java.util.*;
import java.io.*;
public class code{
    public static long n;
    public static long b;
    public static TreeMap<Long,Long> tm;
    public static int k;
    public static long[] div;
    public static long[] cx;
    public static long module(long d,long i){
        long cnt = 0;
        while(d%i==0){
            d/=i;
            cnt++;
        }
        tm.put(i,cnt);
        return d;
    }
    public static void affect(){
        long d = b;
        long i = 2;
        while(i*i<=d){
            if(d%i==0){
                d = module(d,i);
            }
            if(i==2) i++;
            else i+=2;
        }
        if(d>1){
            long cnt = 1;
            tm.put(d,cnt);
        }
    }
    public static void affectDiv(){
        int i=0;
        for(long x:tm.keySet()){
            div[i] = x;
            i++;
        }
    }
    public static long affectation(long dp){
        long i = dp;
        long tmp = 0, mul = 1;
		while (mul <= n / i) {mul *= i; tmp += n / mul;}
		return tmp;
        /*
        long x = 0;
        long d = dp;
        while(d<=n){
            x += n/d;
            d*=dp;
        }
        return x;*/
    }
    public static long conclut(){
        long min = cx[0]/tm.get(div[0]);
        for(int i=1;i<k;i++){
           long d = cx[i]/tm.get(div[i]);
           if(d<min ) min = d;
        }
        return min;
    }
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        b = sc.nextLong();
        tm = new TreeMap<Long,Long>();
        affect();
        k = tm.size();
        div = new long[k];
        cx = new long[k];
        affectDiv();
        for(int i=0;i<k;i++){
            cx[i] = affectation(div[i]);
        }
        long res = conclut();
        System.out.println(res);
    }
}

import java.util.*;

public class r538c {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
//		while(true) {
//			long n=(long)(Math.random()*1e18);
//			long b=(long)(Math.random()*1e12);
			long n=scan.nextLong(), b=scan.nextLong();
			factors=new long[1000001];
			long fin=factorize(b);
			if(fin==b) {
				System.out.println(num(n,b));
				return;
			}
			long res=Long.MAX_VALUE;
			for(int i=2;i<=Math.sqrt(b);i++) {
				if(factors[i]>0) {
					res=Math.min(res,div(num(n,(long)i),factors[i]));
				}
			}
			if(fin>1) {
				res=Math.min(res,num(n,fin));
			}
			System.out.println(res);
//		}
	}
	public static long div(long n, long i) {
		long res=n/i;
		while((res+1)*i<=n) res++;
		while(res*i>n) res--;
		return res;
	}
	public static long num(long n, long i) {
		long ct=i;
		long res=0L;
		while(ct<=n) {
			res+=div(n,ct);
			if(div(n,ct)<i) break;
			ct*=i;
		}
		return res;
	}
	public static long factorize(long b) {
		long bb=b;
		for(int i=2;i<=Math.sqrt(bb);i++) {
			while(b%i==0) {
				factors[i]++;
				b/=i;
			}
		}
		return b;
	}
	static long[] factors;
}
/*
916150178856128256 448561985964
486074803703119168 823004977555
*/

import java.util.*;

/**
 * Copyright © 2019 Chris. All rights reserved.
 *
 * @author Chris
 * 2019/2/25 10:10
 */
public class cfr {

    static void getDiv(Map<Long, Long> div, long n) {
        int sqrt = (int) Math.sqrt(n);
        for (int i = 2; i <= sqrt; i++) {
            if (n % i == 0) {
                getDiv(div, i);
                getDiv(div, n / i);
                return;
            }
        }
        div.put(n, div.getOrDefault(n, 0L) + 1);
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        Map<Long, Long> div = new HashMap<>();
        getDiv(div, b);
        long res = -1;
        for (long key : div.keySet()) {
            long cnt = 0;
            long cur = key;
            while (cur <= n) {
                cnt += n / cur;
                if (n / cur < key) {
                    break;
                }
                cur *= key;
            }
            if (res == -1 || res > cnt / div.get(key)) {
                res = cnt / div.get(key);
            }
        }
        System.out.println(res);
    }
}

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

public class Codeforces {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        long n = in.nextLong();
        long b = in.nextLong();
        Map<Long, Long> numToPow = factorize(b);

        long bestRes = Long.MAX_VALUE;
        for (Long prime : numToPow.keySet()) {
            long pow = numToPow.get(prime);

            long sum = 0;
            long curPrime = prime;
            try {
                while (n / curPrime > 0) {
                    sum += (n / curPrime);
                    curPrime = Math.multiplyExact(curPrime, prime);
                }
            } catch (Exception e) {
            }

            bestRes = Math.min(bestRes, sum / pow);
        }

        out.println(bestRes);
        out.close();
    }

    public static Map<Long, Long> factorize(long numbers) {
        long n = numbers;
        Map<Long, Long> factors = new HashMap<>();
        for (long i = 2; i <= n / i; i++) {
            long count = 0;
            while (n % i == 0) {
                n /= i;
                count++;
            }

            if (count > 0) {
                factors.put(i, count);
            }
        }
        if (n > 1) {
            factors.put(n, 1L);
        }
        return factors;
    }

    public static class InputReader {
        public BufferedReader reader;
        public 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 String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return null;
        }

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

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

        public int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = nextInt();
            }

            return arr;
        }

        public long[] nextLongArr(int n) {
            long[] arr = new long[n];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = nextLong();
            }

            return arr;
        }
    }
}

import java.io.IOException;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main{

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

		FastScanner sc= new FastScanner();
		long n = sc.nextLong();
		long b = sc.nextLong();
		HashMap<Long,Long> map = new HashMap<Long,Long>();
		for(long i=2;i*i<=b;i++){
			while(b%i==0){
				if(map.containsKey(i)){
					map.put(i,map.get(i)+1);
				}else{
					map.put(i,1L);
				}
				b /= i;
			}
		}

		if(b!=1){
			if(map.containsKey(b)){
				map.put(b,map.get(b)+1);
			}else{
				map.put(b,1L);
			}
		}

		long min = 1000000000;
		min *= min;
		for(long e:map.keySet()){
			long div = map.get(e);
			long num = getex(n,e);
			min = Math.min(num/div,min);
		}
		System.out.println(min);

	}

	private static long getex(long n, long e) {
		long ans = 0;
		while(n>0){
			ans += n/e;
			n /= e;
		}
		return ans;
	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

//package feb19;
import java.util.*;
import java.io.*;

public class TrailingZeroes {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		// 6 9 1
		Scanner scn=new Scanner(System.in);

		long n=scn.nextLong();
		long n1=n;
		long b=scn.nextLong();
		/*6!=720 is divisible by 9^1 so answer is 1*/

		/*Finding prime factors of b*/
		long min=Long.MAX_VALUE;
		int count=0;
		long b1=b;
		/*Long i is must not int i else TLE :)*/
		for(long i=2; i*i<=b;i++)
		{
			//System.out.println("I:"+i);
			n=n1;
		//	b=b1;
		//	System.out.println(i+","+b);
			if(b%i==0)
			{
				/*Now we need to find what power of i will make me closest to b*/
				int power=0;
				while(b%i==0)
				{
					b=b/i;
					power++;
				}
			//	System.out.println(b);
				/*What power of i will be in total 1*2*3*4*.... n */
				long powern=0;
				while(n!=0)
				{
					powern=powern+n/i;
					n=n/i;
				}
				long ans=powern/power;
				min=Math.min(min, ans);

				count=1;

			}
		}

		/*agar kisi bhi prime factor se completely divide nahi hua to*/
		if(b!=1)
		{
			long powern=0;

			while(n1!=0)
			{
		//		System.out.println(powern);
				powern=powern+n1/b;
				n1=n1/b;
			}
			if(powern<min)
			{
				min=powern;
			}
		}
		System.out.println(min);

	}
	/*public static class FS
	   {
	      StringTokenizer st;
	      BufferedReader br;

	      FS(InputStream in) throws Exception
	      {
	         br = new BufferedReader(new InputStreamReader(in));
	         st = new StringTokenizer("");
	      }

	      String next() throws Exception
	      {
	         if (st.hasMoreTokens())
	         {
	            return st.nextToken();
	         }
	         st = new StringTokenizer(br.readLine());
	         return next();
	      }

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

	      long nextLong() throws Exception
	      {
	         return Long.parseLong(next());
	      }
	   }*/

}

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

public class Main {
    static FastReader R = new FastReader();
    static StringBuilder sb = new StringBuilder();
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        long n = ll(), b = ll();
        long b_ = b;
        long min = Long.MAX_VALUE;
        for (long i = 2; i <= b_; i++) {
            if (i*i > b)
                i = b_;
            int cnt = 0;
            while (b_%i == 0) {
                cnt++;
                b_ /= i;
            }
            if (cnt == 0)
                continue;
            min = Math.min(min, factorial(n, i)/cnt);
        }
        outln(min);
        flush();
    }
    static long fact(long n, long i) {
        long res = 0;
        while (n%i == 0) {
            res++;
            n /= i;
        }
        return res;
    }
    static long factorial(long n, long i) {
        long res = 0;
        long pembagi = 1;
        while (pembagi <= n/i) {
            pembagi *= i;
            res += n / pembagi;
        }
        return res;
    }
    static void log(Object... objs) {
        out("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            out(", " + objs[i]);
        outln();
        flush();
    }
    static long ll() {
        return R.nextLong();
    }
    static int num() {
        return R.nextInt();
    }
    static String line() {
        return R.nextLine();
    }
    static void flush() {
        System.out.print(sb.toString());
        sb.setLength(0);
    }
    static void out(Object o) {
        sb.append(o.toString());
    }
    static void outln(Object o) {
        out(o);
        outln();
    }
    static void outln() {
        sb.append("\n");
    }
    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer st;
        private StringBuilder sb = new StringBuilder();
        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        }
        public String next() {
            return tokenize() ? st.nextToken() : null;
        }
        private boolean tokenize() {
            if (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    return false;
                }
            }
            return true;
        }
        public String nextLine() {
            if (!tokenize())
                return null;
            sb.setLength(0);
            if (st.hasMoreTokens())
                sb.append(st.nextToken());
            while (st.hasMoreTokens())
                sb.append(' ').append(st.nextToken());
            return sb.length() == 0 ? null : sb.toString();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

public class Main {
    static FastReader R = new FastReader();
    static StringBuilder sb = new StringBuilder();
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        long n = ll(), b = ll();
        long b_ = b;
        long min = Long.MAX_VALUE;
        for (long i = 2; i <= b_; i++) {
            if (i*i > b_)
                i = b_;
            int cnt = 0;
            while (b_%i == 0) {
                cnt++;
                b_ /= i;
            }
            if (cnt == 0)
                continue;
            min = Math.min(min, factorial(n, i)/cnt);
        }
        outln(min);
        flush();
    }
    static long fact(long n, long i) {
        long res = 0;
        while (n%i == 0) {
            res++;
            n /= i;
        }
        return res;
    }
    static long factorial(long n, long i) {
        long res = 0;
        long pembagi = 1;
        while (pembagi <= n/i) {
            pembagi *= i;
            res += n / pembagi;
        }
        return res;
    }
    static void log(Object... objs) {
        out("* " + objs[0]);
        for (int i = 1; i < objs.length; i++)
            out(", " + objs[i]);
        outln();
        flush();
    }
    static long ll() {
        return R.nextLong();
    }
    static int num() {
        return R.nextInt();
    }
    static String line() {
        return R.nextLine();
    }
    static void flush() {
        System.out.print(sb.toString());
        sb.setLength(0);
    }
    static void out(Object o) {
        sb.append(o.toString());
    }
    static void outln(Object o) {
        out(o);
        outln();
    }
    static void outln() {
        sb.append("\n");
    }
    static class FastReader {
        public BufferedReader reader;
        public StringTokenizer st;
        private StringBuilder sb = new StringBuilder();
        public FastReader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
        }
        public String next() {
            return tokenize() ? st.nextToken() : null;
        }
        private boolean tokenize() {
            if (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(reader.readLine());
                } catch (Exception e) {
                    return false;
                }
            }
            return true;
        }
        public String nextLine() {
            if (!tokenize())
                return null;
            sb.setLength(0);
            if (st.hasMoreTokens())
                sb.append(st.nextToken());
            while (st.hasMoreTokens())
                sb.append(' ').append(st.nextToken());
            return sb.length() == 0 ? null : sb.toString();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int tt = 1;
        while(tt-->0) {

            long n = fs.nextLong(), b = fs.nextLong();

            HashMap<Long, Integer> map = new HashMap<Long, Integer>();

            long num = b;

            for(long i=2;i*i<=num;i++){
                int cnt = 0;
                while (num%i==0){
                    num /= i;
                    cnt++;
                }
                if(cnt>0){
                    map.put(i, cnt);
                }
            }
            if(num>1) map.put(num, 1);

            long ans = Long.MAX_VALUE;

            for(long k: map.keySet()){
                ans = Math.min(ans, getPow(n, k)/map.get(k));
            }

            out.println(ans);

        }

        out.close();

    }

    static long getPow(long n, long a){
        long ans =  0;
        int pow = 0;
        long l = 1L;
        while(l<=n/a){
            l *= a;
            pow++;
        }
        ans += (n/l)*pow;
        l /= a; pow--;
        while(l>1){
            ans += ((n/l)-(n/(l*a)))*pow;
            l /= a;
            pow--;
        }
        return ans;
    }

    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 FastScanner{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

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

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

        public char nextChar() {
            return next().toCharArray()[0];
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        int tt = 1;
        while(tt-->0) {

            long n = fs.nextLong(), b = fs.nextLong();

            long ans = Long.MAX_VALUE;

            for(long i=2;i*i<=b;i++){
                int cnt = 0;
                while(b%i==0){
                    b /= i;
                    cnt++;
                }
                if(cnt>0){
                    ans = Math.min(ans, get(n, i)/cnt);
                }
            }

            if(b>1){
                ans = Math.min(ans, get(n, b));
            }

            out.println(ans);

        }

        out.close();

    }

    static long get(long n, long x){
        long ans = 0;
        while(n>0){
            n = n/x;
            ans += n;
        }
        return ans;
    }

    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 FastScanner{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

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

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

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

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

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

        public char nextChar() {
            return next().toCharArray()[0];
        }
    }

}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class TrailingLoves {
	static ArrayList<Integer> ts;

	public static ArrayList<Long> getF(Long n) {

		ArrayList<Long> a = new ArrayList<>();
		int p = 2;
		for (int idx = 0; idx < ts.size() && 1l * p * p <= n; idx++) {
			int c = 0;
			p = ts.get(idx);
			while (n % p == 0) {
				c++;
				n /= p;
			}
			if (c != 0) {
				a.add((long) p);
				a.add((long) c);
			}

		}
		if (n != 1) {
			a.add(n);
			a.add(1l);

		}
		return a;

	}

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		ts = new ArrayList<>();
		int[] primes = new int[1000000 + 1];
		Arrays.fill(primes, 1);

		for (int i = 2; i < primes.length; i++)
			if (primes[i] == 1) {
				ts.add(i);
				for (int j = i * 2; j < primes.length; j += i)
					primes[j] = 0;
			}
		long n = sc.nextLong();
		long m = sc.nextLong();
		ArrayList<Long> a = getF(m);
		long min = Long.MAX_VALUE;
		for (int i = 0; i < a.size(); i += 2) {
			long prime = a.get(i);
			Long c = a.get(i + 1);
			long e = 0;
			while (prime <=(n/a.get(i))) {
				e += n / prime;

				prime *= a.get(i);
			}e+=n/prime;
			min = Math.min(e / c, min);

		}
		pw.println(min);
		pw.flush();

	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			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 IOException {
			return Integer.parseInt(next());
		}

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}

}

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {

    public static void main(String[] args) throws Exception{
	// write your code here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        args = br.readLine().split(" ");
        long n = Long.parseLong(args[0]);
        long b = Long.parseLong(args[1]);
        long ans = Long.MAX_VALUE;
        for(long i=2;i<=b;i++) {
            if(1l*i*i>b) i = b;
            int count = 0;
            while(b%i==0) {
                count++;
                b/=i;
            }
            if(count==0) continue;
            long tmp = 0, mul = 1;
            while(mul <= n/i) {
                mul *= i;
                tmp += n/mul;
            }
            ans = Math.min(ans,tmp/count);
        }
        System.out.println(ans);
    }
}

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

    long n = sc.nextLong();
    long b = sc.nextLong();

    Map<Long, Integer> fact = fact(b);

    long ans = fact.entrySet().stream().mapToLong(entry -> {
      long prime = entry.getKey();
      int num = entry.getValue();
      long sum = calc(n, prime);
      return sum / num;
    }).min().getAsLong();

    System.out.println(ans);
  }

  private static long calc(long n, long prime) {
    if (n == 0) return 0;
    return n / prime + calc(n / prime, prime);
  }

  private static Map<Long, Integer> fact(long b) {
    Map<Long, Integer> fact = new HashMap<>();
    for (long i = 2; i * i <= b; i++) {
        int num = 0;
        while (b % i == 0) {
          b /= i;
          num++;
        }

        if (num > 0) {
          fact.put(i, num);
        }
    }
    if (b != 1) {
      fact.put(b, 1);
    }
    return fact;
  }
}

import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public static final int MOD = 1_000_000_007;
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		long n = f.nextLong(), b = f.nextLong();
		long lim = (long) Math.ceil(Math.sqrt(b));
		long ans = Long.MAX_VALUE;
		for(int i = 2; i <= b && i <= lim; i++) {
			int cnt = 0;
			while(b % i == 0) {
				cnt++;
				b /= i;
			}
			if(cnt == 0) continue;
			long ocnt = 0;
			long pow = i;
			while(pow <= n) {
				ocnt += n / pow;
				if(n/i < pow) break;
				pow *= i;
			}
			ans = Math.min(ans,  ocnt/cnt);
		}
		if(b != 1) {
			int cnt = 1;
			long ocnt = 0;
			long pow = b;
			while(pow <= n) {
				ocnt += n / pow;
				if(n/b < pow) break;
				pow *= b;
			}
			ans = Math.min(ans,  ocnt/cnt);
		}
		out.println(ans);
		out.flush();
	}
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 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 nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();

        List<Long> list = new ArrayList<>();
        Map<Long, Long> map = new HashMap<>();
        for(long i = 2; i * i <= b ; ++i) {
            if(b % i == 0) {
                list.add(new Long(i));
                Long c = new Long(0);
                while(b % i == 0) {
                    ++c;
                    b /= i;
                }

                map.put(i, c);
            }
        }

        if(b > 1) {
            list.add(b);
            map.put(b, 1L);
        }

        Long min = Long.MAX_VALUE;
        for(long p : list) {
            long res = max(n, p) / map.get(p);
            min = Math.min(min, res);
        }

        System.out.println(min);

    }

    static long max(long n, long p) {
        long res = 0;
       while(n > 1){
           res += n / p;
           n /= p;
       }

        return res;
    }
}

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Main
{
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int ni() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nl() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nd() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }
    static class Pair implements Comparable<Pair> {
        int x,y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
        public int compareTo(Pair o) {
            if(this.x!=o.x)
                return this.x-o.x;
            return this.y-o.y;
        }
        public String toString(){
            return x+" "+y;
        }
    }
    static long count(long n,long fac) {
        long res=0;
        while(n>0) {
            //System.out.println(n+" "+fac+" "+res);
            res+=n/fac;
            n/=fac;
        }
        return res;
    }
    static long MOD=(long)1e9+7;
    static PrintWriter pw = new PrintWriter(System.out,true);
    static StringBuilder sb = new StringBuilder();
    public static void main(String[] args) throws IOException
    {
        Reader sc=new Reader();
        //Scanner sc = new Scanner(System.in);
        //Code start from here
        long n = sc.nl(),b = sc.nl();
        ArrayList<Long> factor= new ArrayList<>();
        ArrayList<Long> power = new ArrayList<>();
        for(long i =2;i*i<=b;i++) {
            if(b%i==0) {
                factor.add(i);
                long count=0;
                while(b%i==0) {
                    count++;
                    b/=i;
                }
                power.add(count);
            }
        }
        if(b>1) {
            factor.add(b);
            power.add(1l);
        }
        long ans = Long.MAX_VALUE;
        for(int i =0;i<factor.size();i++) {
            //System.out.println("start");
            long z = count(n,factor.get(i))/power.get(i);
            //System.out.println(ans+" "+z+" "+factor.get(i)+" "+power.get(i));
            ans=min(ans,z);
            //System.out.println(ans);
        }
        System.out.println(ans);

        pw.print(sb);
        pw.flush();
        pw.close();
    }
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Liavontsi Brechka
 */
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);
        CZamikayushieNuli solver = new CZamikayushieNuli();
        solver.solve(1, in, out);
        out.close();
    }

    static class CZamikayushieNuli {
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.in = in;

            long n = nl();
            long b = nl();

            Map<Long, Long> map = new HashMap<>();
            for (long i = 2; i * i <= b; i++) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    map.put(i, count);
                }
            }

            if (b > 1) map.put(b, 1L);

            Map<Long, Long> map2 = new HashMap<>();
            for (Long key : map.keySet()) {
                long count = 0;
                long nextN = n;

                long next = key;

                while (nextN >= next) {
                    count += nextN / next;
                    nextN /= next;
                }

                map2.put(key, count);
            }

            long res = Long.MAX_VALUE;
            for (Map.Entry<Long, Long> e : map.entrySet()) {
                res = Math.min(res, map2.get(e.getKey()) / e.getValue());
            }

            out.print(res == Integer.MAX_VALUE ? 0 : res);
        }

        private long nl() {
            return in.nextLong();
        }

    }

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

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

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

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

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Main {

  static String baseConversion(String number,
                                 int sBase, int dBase)
                                  {
        // Parse the number with source radix
        // and return in specified radix(base)
        return Integer.toString(
            Integer.parseInt(number, sBase),
            dBase);
    }
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        InputReader in = new InputReader(inputStream);
        String q = in.next();
    //    System.out.println(q);
        String q1 = in.next();
      //  System.out.println(q1);

        long n =  Long.parseLong(q);
        Long b =  Long.parseLong(q1);
        HashMap<Long,Long> ca= new HashMap<Long,Long>();

        long qs = (long)Math.sqrt(b);
        for(long j=2 ; j<=qs+1 ;j++) {

            Long count = 0l;
            if(b%j == 0) {

              while(b%j == 0) {
                 count++;
                 b = b/j;
              }

              ca.put(j,count);

            }

        }

        if(b > 1) {
            ca.put(b,1l);

        }

        long max = Long.MAX_VALUE;
        long count = 0l;
        for (Map.Entry<Long,Long> entry : ca.entrySet()) {
            long val = entry.getKey();
             count = 0l;
            long  m = n;
            while(m/val> 0) {
                count +=  m/val;
                m= m/val;
            }

            count = count/entry.getValue();
            if(count  < max) {
                max = count;
            }
        }

         System.out.println(max);

    }

    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 nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
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 Abhas Jain
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nl();
            long b = in.nl();
            long pil = b;
            HashMap<Long, Long> hashMap = new HashMap<>();
            for (long i = 2L; i * i <= pil; ++i) {
                if (b % i == 0L) {
                    long count = 0L;
                    while (b % i == 0L) {
                        b /= i;
                        count++;
                    }
                    hashMap.put(i, count);
                }
            }
            if (b != 1L) hashMap.put(b, 1L);
            long min = Long.MAX_VALUE;
            for (long f : hashMap.keySet()) {
                long count = 0L;
                long fact = f;
                while (true) {
                    count += (n / fact);
                    if (fact <= (n / f)) fact *= f;
                    else break;
                }
                min = Math.min(min, count / hashMap.get(f));
            }
            out.print(min);
        }

    }

    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 long nl() {
            return Long.parseLong(next());
        }

    }
}

import java.util.*;
import java.io.*;
public class C538
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = sc.nextLong(); long b = sc.nextLong(); long ans = Long.MAX_VALUE;
        Map<Long, Long> powers = factorize(b);
        Map<Long, Long> floor = new HashMap<>();
        for (Long factor: powers.keySet()) {
            long cur = factor; long temp = n; long toDo = 0;
            while (temp / cur > 0) {
                toDo += (temp / cur);
                if ((cur * factor) / factor == cur) {
                    cur *= factor;
                } else break;
            }
            floor.put(factor, toDo);
        }
        for (Long factor: floor.keySet()) {
            long best = floor.get(factor);
            ans = Math.min(ans, best / powers.get(factor));
        }
        out.println(ans);
        out.close();
    }

    static Map<Long, Long> factorize(long n) {
        Map<Long, Long> ret = new HashMap<>(); long cur = n;
        for (long i = 2; i <= Math.sqrt(n); i++) {
            while (cur % i == 0) {
                cur /= i;
                ret.put(i, ret.getOrDefault(i, (long) 0) + 1);
            }
            if (cur == 1) break;
        }
        if (cur != 1) {
            ret.put(cur, (long) 1);
        }
        return ret;
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}

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

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

		long n = sc.nextLong();
		long b = sc.nextLong();

		long res = Long.MAX_VALUE;

		List<long[]> factors = getFactors(b);

		for (long[] factor : factors) {
			long f = factor[0];
			long p = factor[1];

			long times = getTimes(n, f);

			long full = times / p;

			res = Math.min(res, full);
		}

		System.out.println(res);
	}

	public static long getTimes(long num, long factor) {
		long times = 0;

		while (num >= factor) {
			times += (num / factor);
			num /= factor;
		}

		return times;
	}

	// Get factors and powers.
	public static List<long[]> getFactors(long num) {
		List<long[]> factors = new ArrayList<>();

		long f = 2;

		while (f*f <= num) {
			if (num % f == 0) {
				long p = 0;

				while (num % f == 0) {
					p++;
					num /= f;
				}

				factors.add(new long[] {f, p});
			}

			f++;
		}

		if (num > 1) {
			factors.add(new long[] {num, 1});
		}

		return factors;
	}
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class C_Round_538_Div2 {

    public static long MOD = 998244353;
    static long[][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        long n = in.nextLong();
        long b = in.nextLong();
        long result = n;
        for (long i = 2; i <= b / i; i++) {
            if (b % i == 0) {
                int count = 0;
                while (b % i == 0) {
                    count++;
                    b /= i;
                }
                //System.out.println(count + " " + i);
                long c = 0;
                long start = n;
                long index = 1;
                while (start >= i && start > 0) {
                    start /= i;
                    c++;
                    index *= i;
                }
                long total = 0;
                long last = 0;

                for (long j = c; j > 0; j--) {
                    long cur = n / index;
                    cur -= last;
                    //System.out.println(cur + " " + j + " " + index);
                    total += cur * j;
                    last += cur;
                    index /= i;
                }
                //System.out.println("Total " + total + " " + i);

                result = Long.min(result, total / count);
            }
        }
        if (b != 1) {
            long i = b;
            int count = 0;
            while (b % i == 0) {
                count++;
                b /= i;
            }
            int c = 0;
            long start = n;
            long index = 1;
            while (start >= i && start > 0) {
                start /= i;
                c++;
                index *= i;
            }
            //System.out.println(index + " " + i + " " + c + " " + start);
            long total = 0;
            long last = 0;

            for (int j = c; j > 0; j--) {
                long cur = n / index;
                cur -= last;
                total += cur * j;
                last += cur;
                index /= i;
            }
            //System.out.println("Total " + total + " " + i);
            result = Long.min(result, total / count);
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

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

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

    import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static ArrayList<Integer> adj[];
	// static PrintWriter out = new PrintWriter(System.out);

	static int[][] notmemo;
	static int k;
	static int[] a;
	static int b[];
	static int m;

	static class Pair implements Comparable<Pair> {
		int c;
		int d;
		public Pair(int b, int l) {
			c = b;
			d = l;
		}
		@Override
		public int compareTo(Pair o) {
		return o.d-this.d;
		}

	}

	static Pair s1[];
	static ArrayList<Pair> adjlist[];
	// static char c[];
	public static long mod = (long) (1e9 + 7);
	static int V;
	static long INF = (long) 1E16;
	static int n;
	static char c[];
	static int d[];
	static int z;
	static Pair p[];
static int R;
static int C;
static int K;
static long grid[][];
static Scanner sc = new Scanner(System.in);
static int x[];
static int y[];
static PrintWriter out = new PrintWriter(System.out);
public static void main(String args[]) throws Exception {
long n=sc.nextLong();
long b=sc.nextLong();
TreeSet<Long>factors = new TreeSet<Long>();		//take abs(N) in case of -ve integers
long N=b;
sieve((int) (1e6+5));
int idx =0;long p = primes.get(idx);
long min=(long) 1e18;
while(1l*p * p <= N)
{
	long count=0;

	while(N % p == 0) { factors.add( p); N /= p; count++;}
	if(count==0) {
		p = primes.get(++idx);
		continue;

	}
	long x=1;
	long prev=x;
	long next=p;
	ArrayList<Long> pow=new ArrayList<>();

	while(true) {
		if(x<prev||x>n/p)
			break;

		x*=next;
		pow.add(x);
		prev=x;
	}

	long fac=0;
	for(long xx:pow) {
		fac+=(n/xx);
	}

	p = primes.get(++idx);
	min=Math.min(fac/count,min);

}

if(N != 1)	{
	factors.add(N);

	long count=0;
	p=N;
	count++;
	long x=1;
	long prev=x;
	long next=p;
	ArrayList<Long> pow=new ArrayList<>();
	while(true) {
		if(x<prev||x>n/next)
				break;
		x*=next;

		pow.add(x);
		prev=x;
	}

	long fac=0;
	for(long xx:pow) {
		fac+=(n/xx);
	}

	min=Math.min(fac/count,min);

}
System.out.println(min);

//20833333333333332
//249999999999999995

}
static int aa;
static int bb;
static int cc;
static int dp(int n) {
	if(n==0)
	return 0;
if(n<0) {
return  -1000000;
}
if(div4[n]!=-1)
	return div4[n];
int ans=-1000000;
ans=Math.max(ans,1+dp(n-aa));
ans=Math.max(ans,1+dp(n-bb));
ans=Math.max(ans,1+dp(n-cc));
return div4[n]=ans;
}
static int color=0;
static int[] compreessarray(int c[]) {
	Stack<Integer> st=new Stack<>();
	for (int i = 0; i < c.length; i++) {
		if(st.isEmpty()||c[i]!=st.peek())
		st.add(c[i]);
	}
	b=new int[st.size()];
	for (int i = b.length-1; i>=0; i--) {
		b[i]=st.pop();
	}
	return b;
}
static int div4[];
static int s[];

static  TreeSet<Integer> ts=new TreeSet();
static HashMap<Integer, Integer> compress(int a[]) {
		 ts = new TreeSet<>();
		HashMap<Integer, Integer> hm = new HashMap<>();
		for (int x : a)
			ts.add(x);
		for (int x : ts) {
			hm.put(x, hm.size() + 1);
		}
		return hm;
	}

	static  class FenwickTree { // one-based DS

		int n;
		int[] ft;

		FenwickTree(int size) { n = size; ft = new int[n+1]; }

		int rsq(int b) //O(log n)
		{
			int sum = 0;
			while(b > 0) { sum += ft[b]; b -= b & -b;}		//min?
			return sum;
		}

		int rsq(int a, int b) { return rsq(b) - rsq(a-1); }

		void point_update(int k, int val)	//O(log n), update = increment
		{
			while(k <= n) { ft[k] += val; k += k & -k; }		//min?
		}
	}
	static ArrayList<Integer> euler=new ArrayList<>();

	static ArrayList<Integer> arr;

static int[] total;
static TreeMap<Integer,Integer> map1;

		static int zz;
//static int dp(int idx,int left,int state) {
//if(idx>=k-((zz-left)*2)||idx+1==n) {
//	return 0;
//}
//if(memo[idx][left][state]!=-1) {
//	return memo[idx][left][state];
//}
//int ans=a[idx+1]+dp(idx+1,left,0);
//if(left>0&&state==0&&idx>0) {
//	ans=Math.max(ans,a[idx-1]+dp(idx-1,left-1,1));
//}
//return memo[idx][left][state]=ans;
//}21
static HashMap<Integer,Integer> map;
static int maxa=0;
static int ff=123123;

static int[][] memo;

	static long modmod=998244353;
	static int dx[]= {1,-1,0,0};
	 static int dy[]= {0,0,1,-1};
	static class BBOOK implements Comparable<BBOOK>{
		int t;
		int alice;
		int bob;
		public BBOOK(int x,int y,int z) {
		t=x;
		alice=y;
		bob=z;
		}
		@Override
		public int compareTo(BBOOK o) {
			return this.t-o.t;
		}
	}
	private static long lcm(long a2, long b2) {
	return (a2*b2)/gcd(a2,b2);
	}
	static class Edge implements Comparable<Edge>
	{
		int node;long cost ; long time;

		Edge(int a, long b,long c) { node = a;	cost = b; time=c; }

		public int compareTo(Edge e){ return Long.compare(time,e.time);	}
	}

        static void sieve(int N)	// O(N log log N)
	{
		isComposite = new int[N+1];
		isComposite[0] = isComposite[1] = 1;			// 0 indicates a prime number
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i) 					//can loop till i*i <= N if primes array is not needed O(N log log sqrt(N))
			if (isComposite[i] == 0) 					//can loop in 2 and odd integers for slightly better performance
			{
				primes.add(i);
				if(1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)	// j = i * 2 will not affect performance too much, may alter in modified sieve
						isComposite[j] = 1;
			}
	}
    static TreeSet<Integer> factors;
    static TreeSet<Integer> primeFactors(int N)		// O(sqrt(N) / ln sqrt(N))
	{
		 factors = new TreeSet<Integer>();		//take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while(1l*p * p <= N)
		{
			while(N % p == 0) { factors.add(p); N /= p; }
			p = primes.get(++idx);
		}

		if(N != 1)						// last prime factor may be > sqrt(N)
			factors.add(N);				// for integers whose largest prime factor has a power of 1
		return factors;
	}

	static class UnionFind {
		int[] p, rank, setSize;
		int numSets;
		int max[];

		public UnionFind(int N) {
			p = new int[numSets = N];
			rank = new int[N];
			setSize = new int[N];
			for (int i = 0; i < N; i++) {
				p[i] = i;
				setSize[i] = 1;
			}
		}

		public int findSet(int i) {
			return p[i] == i ? i : (p[i] = findSet(p[i]));
		}

		public boolean isSameSet(int i, int j) {
			return findSet(i) == findSet(j);
		}
		public int chunion(int i,int j, int x2) {
			if (isSameSet(i, j))
				return 0;
			numSets--;
			int x = findSet(i), y = findSet(j);
			int z=findSet(x2);
			p[x]=z;;
			p[y]=z;
		return x;
		}

		public void unionSet(int i, int j) {
			if (isSameSet(i, j))
				return;
			numSets--;
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y]) {
				p[y] = x;
				setSize[x] += setSize[y];

			} else {
				p[x] = y;
				setSize[y] += setSize[x];
				if (rank[x] == rank[y])
					rank[y]++;

			}
		}

		public int numDisjointSets() {
			return numSets;
		}

		public int sizeOfSet(int i) {
			return setSize[findSet(i)];
		}
	}

	static class Quad implements Comparable<Quad> {
		int u;
		int v;
		char state;
		int turns;

		public Quad(int i, int j, char c, int k) {
			u = i;
			v = j;
			state = c;
			turns = k;
		}

		public int compareTo(Quad e) {
			return (int) (turns - e.turns);
		}

	}

	static long manhatandistance(long x, long x2, long y, long y2) {
		return Math.abs(x - x2) + Math.abs(y - y2);
	}

	static long fib[];

	static long fib(int n) {
		if (n == 1 || n == 0) {
			return 1;
		}
		if (fib[n] != -1) {
			return fib[n];
		} else
			return fib[n] = ((fib(n - 2) % mod + fib(n - 1) % mod) % mod);
	}

	static class Point  implements Comparable<Point>{
		long x, y;

		Point(long counth, long counts) {
			x = counth;
			y = counts;
		}

		@Override
		public int compareTo(Point p )
		{
			return Long.compare(p.y*1l*x, p.x*1l*y);
		}
	}

	static TreeSet<Long> primeFactors(long N) // O(sqrt(N) / ln sqrt(N))
	{
		TreeSet<Long> factors = new TreeSet<Long>(); // take abs(N) in case of -ve integers
		int idx = 0, p = primes.get(idx);

		while (p * p <= N) {
			while (N % p == 0) {
				factors.add((long) p);
				N /= p;
			}
			if (primes.size() > idx + 1)
				p = primes.get(++idx);
			else
				break;
		}

		if (N != 1) // last prime factor may be > sqrt(N)
			factors.add(N); // for integers whose largest prime factor has a power of 1
		return factors;
	}

	static boolean visited[];

	/**
	 * static int bfs(int s) { Queue<Integer> q = new LinkedList<Integer>();
	 * q.add(s); int count=0; int maxcost=0; int dist[]=new int[n]; dist[s]=0;
	 * while(!q.isEmpty()) {
	 *
	 * int u = q.remove(); if(dist[u]==k) { break; } for(Pair v: adj[u]) {
	 * maxcost=Math.max(maxcost, v.cost);
	 *
	 *
	 *
	 * if(!visited[v.v]) {
	 *
	 * visited[v.v]=true; q.add(v.v); dist[v.v]=dist[u]+1; maxcost=Math.max(maxcost,
	 * v.cost); } }
	 *
	 * } return maxcost; }
	 **/

	static boolean[] vis2;

	static boolean f2 = false;

	static long[][] matMul(long[][] a2, long[][] b, int p, int q, int r) // C(p x r) = A(p x q) x (q x r) -- O(p x q x
																			// r)
	{
		long[][] C = new long[p][r];
		for (int i = 0; i < p; ++i) {
			for (int j = 0; j < r; ++j) {
				for (int k = 0; k < q; ++k) {
					C[i][j] = (C[i][j] + (a2[i][k] % mod * b[k][j] % mod)) % mod;
					C[i][j] %= mod;
				}

			}
		}
		return C;
	}
	public static int[] schuffle(int[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			int temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static boolean vis[];
	static HashSet<Integer> set = new HashSet<Integer>();

	static long modPow(long ways, long count, long mod) // O(log e)
	{
		ways %= mod;
		long res = 1;
		while (count > 0) {
			if ((count & 1) == 1)
				res = (res * ways) % mod;
			ways = (ways * ways) % mod;
			count >>= 1;
		}
		return res % mod;
	}

	static long gcd(long l, long o) {
		if (o == 0) {
			return l;
		}
		return gcd(o, l % o);
	}

	static int[] isComposite;
	static int[] valid;

	static ArrayList<Integer> primes;
	static ArrayList<Integer> l1;

	static TreeSet<Integer> primus = new TreeSet<Integer>();

	static void sieveLinear(int N)
	{
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primus.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primus)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}

	public static long[] schuffle(long[] a2) {
		for (int i = 0; i < a2.length; i++) {
			int x =  (int) (Math.random() * a2.length);
			long temp = a2[x];
			a2[x] = a2[i];
			a2[i] = temp;
		}
		return a2;
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			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 IOException {
			return Integer.parseInt(next());
		}

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}

		public int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}
	public static int[] sortarray(int a[]) {
		schuffle(a);
		Arrays.sort(a);
		return a;
		}
		public static long[] sortarray(long a[]) {
			schuffle(a);
			Arrays.sort(a);
			return a;
		}
		public static int[] readarray(int n) throws IOException {
			int a[]=new int[n];
			for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			}
			return a;
		}
		public static long[] readlarray(int n) throws IOException {
			long a[]=new long[n];
			for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextLong();
			}
			return a;
		}
}

import java.util.Scanner;

public class A17 {
    public static long f(long n, long l) {
        long ans = 0;
        while (n >= l) {
            n /= l;
            ans += n;
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long del = 2;
        long n = in.nextLong();
        long b = in.nextLong();
        long a[] = new long[100];
        long c[] = new long[100];
        int r = 0;
        while (b > 1 && del * del <= b) {
            if (b % del == 0) {
                b /= del;

                if (r == 0) {
                    a[r] = del;
                    c[r] = 1;
                    r++;
                } else {
                    if (del != a[r - 1]) {
                        a[r] = del;
                        c[r] = 1;
                        r++;
                    } else {
                        c[r - 1]++;
                    }
                }
            } else {
                del++;
            }
        }
        if (b > 1) {
            if (r == 0) {
                a[r] = b;
                c[r] = 1;
                r++;
            } else {
                if (b != a[r - 1]) {
                    a[r] = b;
                    c[r] = 1;
                    r++;
                } else {
                    c[r - 1]++;
                }
            }
        }

        long mn = f(n, a[0]) / c[0];
        for (int i = 1; i < r; i++) {
            long res = f(n, a[i]) / c[i];
            mn = Math.min(mn, res);
        }
        System.out.println(mn);

    }

}

import com.sun.org.apache.xpath.internal.operations.Plus;

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

public class Main {
    public static void main(String[] args)  {
        __SolutionBase begin = new __SolutionBase();
        begin.Solve();
    }
}

class __SolutionBase {

    public void Solve() {
        init();
        Solution();
        out.close();
    }

    private void Solution() {
        long n = readLong();

        long b = readLong();

        long answer = Long.MAX_VALUE;

        for (long i = 2;i <= b;i++){
            if (i*i > b) i = b;
            int count = 0;
            while (b % i == 0){
                b /= i;
                count++;
            }

            if (count == 0)
                continue;

            long tempAnswer = 0;
            long per = 1;
            while (n / i >= per){
                per *= i;
                tempAnswer += n / per;
            }

            answer = Math.min(answer,tempAnswer/count);
        }

        out.println(answer);
    }

    /**
     * readLong, readDouble and other are similar
     *
     * @return int type from input
     */
    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
    /**
     * Tokens are separated by space or endExclusive of line
     *
     * @return non-empty string token from input (or null if there is no any token)
     */
    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    /**
     * @return whole line from input
     */
    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer(" ");

    /**
     * For local testing I use pair 'input.txt'/'output.txt' in the project root
     */
    private void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (FileNotFoundException e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }
}

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

public class scratch_25 {
    static class Reader {
        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("");
        }

        /** 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 double nextDouble() throws IOException {
            return Double.parseDouble( next() );
        }
        static long nextLong() throws IOException{
            return Long.parseLong(next());
        }
    }
    static class pair
    {
        long first, second;
        public pair(long first, long second)
        {
            this.first = first;
            this.second = second;
        }
    }
    // To find the power of a prime p in
// factorial N
    static long findPowerOfP(long n, long p)
    {
        long count = 0;
        long r = p;
        while (n>0)
        {
            n/=r;

            // calculating Math.floor(n/r)
            // and adding to the count
            count += n ;

            // increasing the power of p
            // from 1 to 2 to 3 and so on

        }
        return count;
    }

    // returns all the prime factors of k

    // Returns largest power of k that
// divides n!
    static long largestPowerOfK(long n, long k)
    {
        Vector<pair > vec = new Vector<pair>();
        vec = primeFactorsofK(k);
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < vec.size(); i++){
          //  System.out.println("bhosdike");

            // calculating minimum power of all
            // the prime factors of k
            ans = Math.min(ans, findPowerOfP(n,
                    vec.get(i).first) / vec.get(i).second);}

        return ans;
    }
    public static Vector<pair> primeFactorsofK(long n)
    {
        Vector<pair> ans = new Vector<pair>();
        // Print the number of 2s that divide n
        long count=0;
        while (n%2==0)
        {
            count++;
           // System.out.print(2 + " ");
            n /= 2;
        }
        if(count>0){
        ans.add(new pair(2,count));}

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            long count1=0;
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                count1++;
               // System.out.print(i + " ");
                n /= i;
            }
            if(count1>0){
            ans.add(new pair(i,count1));}
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if(n>2){
            ans.add(new pair(n,1));
        }
//

        return ans;
    }

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        long n= Reader.nextLong();
        long b= Reader.nextLong();
        System.out.println(largestPowerOfK(n,b));

      //  long u= (long)999999999989;
       // System.out.println();

        }
//    static boolean isPrime(long n)
//    {
//        // Corner cases
//        if (n <= 1)
//            return false;
//        if (n <= 3)
//            return true;
//
//        // This is checked so that we can skip
//        // middle five numbers in below loop
//        if (n % 2 == 0 || n % 3 == 0)
//            return false;
//
//        for (int i = 5; i * i <= n; i = i + 6)
//            if (n % i == 0 || n % (i + 2) == 0)
//                return false;
//
//        return true;
//    }

    static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
    static boolean ans(int check, long arr[],int n,int med,int k){
        long ans=0;
        for (int i = med; i <n ; i++) {
            if(check>=arr[i]){
                ans+=check-arr[i];
            }
        }
        return ans<=k;

    }

    static long smallestDivisor(long n)
    {
        // if divisible by 2
        if (n % 2 == 0)
            return 2;

        // iterate from 3 to sqrt(n)
        for (int i = 3; (long)i *(long) i <= n; i += 2) {
            if (n % i == 0)
                return i;
        }

        return n;
    }
    static boolean isPrime(long n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (long i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }
static BigDecimal fd(int mid, double h, double c){
        BigDecimal a = new BigDecimal((h+c)/(2.0));
        BigDecimal b = new BigDecimal((h-c)/(2.0*mid));
        BigDecimal cd = a.add(b);
        return cd;

}
    static   int partition(double arr[],int arr1[],int arr2[], int low, int high)
    {
        double pivot = arr[high];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            // If current element is smaller than the pivot
            if (arr[j] < pivot)
            {
                i++;

                // swap arr[i] and arr[j]
                double temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                int temp1=arr1[i];
                arr1[i]=arr1[j];
                arr1[j]=temp1;
                int temp2=arr2[i];
                arr2[i]=arr2[j];
                arr2[j]=temp2;

            }
        }

        // swap arr[i+1] and arr[high] (or pivot)
        double temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;
        int temp1= arr1[i+1];
        arr1[i+1]=arr1[high];
        arr1[high]= temp1;
        int temp2= arr2[i+1];
        arr2[i+1]=arr2[high];
        arr2[high]= temp2;

        return i+1;
    }

    /* The main function that implements QuickSort()
      arr[] --> Array to be sorted,
      low  --> Starting index,
      high  --> Ending index */
    static void sort(double arr[],int arr1[],int arr2[], int low, int high)
    {
        if (low < high)
        {
            /* pi is partitioning index, arr[pi] is
              now at right place */
            int pi = partition(arr,arr1,arr2, low, high);

            // Recursively sort elements before
            // partition and after partition
            sort(arr,arr1,arr2, low, pi-1);
            sort(arr,arr1, arr2,pi+1, high);
        }
    }
    static int removeDuplicates(int arr[], int n)
    {
        // Return, if array is empty
        // or contains a single element
        if (n==0 || n==1)
            return n;

        int[] temp = new int[n];

        // Start traversing elements
        int j = 0;
        for (int i=0; i<n-1; i++)
            // If current element is not equal
            // to next element then store that
            // current element
            if (arr[i] != arr[i+1])
                temp[j++] = arr[i];

        // Store the last element as whether
        // it is unique or repeated, it hasn't
        // stored previously
        temp[j++] = arr[n-1];

        // Modify original array
        for (int i=0; i<j; i++)
            arr[i] = temp[i];

        return j;
    }
    static long maxPrimeFactors( long n)
    {
        // Initialize the maximum prime
        // factor variable with the
        // lowest one
        long maxPrime = -1;

        // Print the number of 2s
        // that divide n
        while (n % 2 == 0) {
            maxPrime = 2;

            // equivalent to n /= 2
            n >>= 1;
        }

        // n must be odd at this point,
        // thus skip the even numbers
        // and iterate only for odd
        // integers
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            while (n % i == 0) {
                maxPrime = i;
                n = n / i;
            }
        }

        // This condition is to handle
        // the case when n is a prime
        // number greater than 2
        if (n > 2)
            maxPrime = n;

        return maxPrime;
    }

}

import com.sun.org.apache.xpath.internal.operations.Plus;

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

public class Main {
    public static void main(String[] args)  {
        __SolutionBase begin = new __SolutionBase();
        begin.Solve();
    }
}

class __SolutionBase {

    public void Solve() {
        init();
        Solution();
        out.close();
    }

    private void Solution() {
        long n = readLong();

        long b = readLong();

        long answer = Long.MAX_VALUE;

        for (long i = 2;i <= b;i++){
            if (i*i > b) i = b;
            int count = 0;
            while (b % i == 0){
                b /= i;
                count++;
            }

            if (count == 0)
                continue;

            long tempAnswer = 0;
            double per = i;
            while ((long)(n / per) >= 1){
                tempAnswer += n /(long)per;
                per *= i;
            }

            answer = Math.min(answer,tempAnswer/count);
        }

        out.println(answer);
    }

    /**
     * readLong, readDouble and other are similar
     *
     * @return int type from input
     */
    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
    /**
     * Tokens are separated by space or endExclusive of line
     *
     * @return non-empty string token from input (or null if there is no any token)
     */
    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    /**
     * @return whole line from input
     */
    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer(" ");

    /**
     * For local testing I use pair 'input.txt'/'output.txt' in the project root
     */
    private void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (FileNotFoundException e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }
}

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

public class C implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		long n = scn.nextLong(), b = scn.nextLong();
		long min = Long.MAX_VALUE;
		for (long i = 2; i * i <= b; i++) {
			int k = 0;
			while (b % i == 0) {
				k++;
				b /= i;
			}
			if (k != 0) {
				long x = 0, y = 1;
				while (Math.pow(i, y) <= n) {
					long v = (long) Math.pow(i, y);
					x += n / v;
					y++;
				}
				min = Math.min(min, x / k);
			}
		}
		if(b != 1) {
			long x = 0, y = 1;
			while (Math.pow(b, y) <= n) {
				long v = (long) Math.pow(b, y);
				x += n / v;
				y++;
			}
			min = Math.min(min, x);
		}
		out.println(min);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new C(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

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

		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++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

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

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

		char[] next(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);
		}

		int nextInt() {
			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();
			}
		}

		long nextLong() {
			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();
			}
		}

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

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

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

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

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

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}
	}
}

import java.awt.*;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();long b=sc.nextLong();
        HashMap<Long,Long> bFactors=factors(b);
        HashMap<Long,Long> nFactors=new HashMap<>();
        for (long i:bFactors.keySet()){
            long x=n;long cnt=0;
            while (x>0){
                x/=i;
                cnt+=x;
            }
            nFactors.put(i,cnt);
        }
        long min=Long.MAX_VALUE;
        for (long i:bFactors.keySet()){
            min=Math.min(min,nFactors.get(i)/bFactors.get(i));
        }
        System.out.println(min);

    }
    static HashMap<Long,Long> factors(long b){
        HashMap<Long,Long> map=new HashMap<>();
        int bb=(int) Math.sqrt(b);
        if (b%2==0){
            long x=0;
            while (b%2==0){
                b=b/2;
                x++;
            }
            map.put(2L,x);
        }
        for (int i=3;i<=bb;i++){
            if (b%i==0){
                map.put((long)i,0L);
                int x=0;
                while (b%i==0){
                    b=b/i;
                    x++;
                }
                map.put((long)i,(long)x);
            }
        }
        if (b>2)map.put(b,1L);
        return map;
    }
}

	                                                    import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.TreeMap;

	                public class Solution2 implements Runnable
	                {
	                    static final long MAX = 464897L;
	                    static class InputReader
	                    {
	                        private InputStream stream;
	                        private byte[] buf = new byte[1024];
	                        private int curChar;
	                        private int numChars;
	                        private SpaceCharFilter filter;
	                        private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	                        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 String nextLine()
	                        {
	                            String str = "";
	                            try
	                            {
	                                str = br.readLine();
	                            }
	                            catch (IOException e)
	                            {
	                                e.printStackTrace();
	                            }
	                            return str;
	                        }
	                        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 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 double nextDouble()
	                        {
	                            int c = read();
	                            while (isSpaceChar(c))
	                                c = read();
	                            int sgn = 1;
	                            if (c == '-')
	                            {
	                                sgn = -1;
	                                c = read();
	                            }
	                            double res = 0;
	                            while (!isSpaceChar(c) && c != '.')
	                            {
	                                if (c == 'e' || c == 'E')
	                                    return res * Math.pow(10, nextInt());
	                                if (c < '0' || c > '9')
	                                    throw new InputMismatchException();
	                                res *= 10;
	                                res += c - '0';
	                                c = read();
	                            }
	                            if (c == '.')
	                            {
	                                c = read();
	                                double m = 1;
	                                while (!isSpaceChar(c))
	                                {
	                                    if (c == 'e' || c == 'E')
	                                        return res * Math.pow(10, nextInt());
	                                    if (c < '0' || c > '9')
	                                        throw new InputMismatchException();
	                                    m /= 10;
	                                    res += (c - '0') * m;
	                                    c = read();
	                                }
	                            }
	                            return res * sgn;
	                        }

	                        public String readString()
	                        {
	                            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 boolean isSpaceChar(int c)
	                        {
	                            if (filter != null)
	                                return filter.isSpaceChar(c);
	                            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	                        }

	                        public String next()
	                        {
	                            return readString();
	                        }

	                        public interface SpaceCharFilter
	                        {
	                            public boolean isSpaceChar(int ch);
	                        }
	                    }

	                    public static void main(String args[]) throws Exception
	                    {
	                        new Thread(null, new Solution2(),"Solution2",1<<26).start();
	                    }
	                    static long gcd(long a, long b)
	                    {
	                      if (b == 0)
	                        return a;
	                      return gcd(b, a % b);
	                    }
	                    static long lcm(long a,long b) {
	                        return (a*b)/gcd(a,b);
	                    }
	                    int maxn = 1000005;
	                    long MOD = 1000000007;

	                    TreeMap<Long,Long> dp = new TreeMap();
	                    TreeMap<Integer,ArrayList<Integer>> tree = new TreeMap();
	                    int[] val;
	                    int[] ans;
	                    long[] arr;
	                    ArrayList<Long> prim = new ArrayList<Long>();
	                    public void run()
	                    {
	                        InputReader sc = new InputReader(System.in);
	                        PrintWriter w = new PrintWriter(System.out);
	                        sieveOfEratosthenes(1000005);
	                        long n = sc.nextLong();
	                        long b = sc.nextLong();
	                        TreeMap<Long,Integer> factorize = new TreeMap<Long,Integer>();
	                        for(int i = 0;i < prim.size();i++) {
	                        	while(b % prim.get(i) == 0) {
	                        		b = b / prim.get(i);
	                        		if(factorize.containsKey(prim.get(i))) {
	                        			factorize.put(prim.get(i), factorize.get(prim.get(i)) + 1);
	                        		}else {
	                        			factorize.put(prim.get(i), 1);
	                        		}
	                        	}
	                        }
	                        if(b != 1) {
	                        	factorize.put(b, 1);
	                        }
	                        long min = Long.MAX_VALUE;
	                        for(Long key: factorize.keySet()) {
	                        	long tans = calc(key,factorize.get(key),n);
	                        	min = Math.min(min, tans);
	                        }

	                        w.println(min);
	                        w.close();
	                    }
	                    long calc(long prime,long val,long n) {
	                    	long ans = 0;
	                    	long temp = prime;
	                    	while(prime <= n && prime > 0) {
	                    		ans += n/prime;
	                    		if(n/temp < prime) {
	                    			break;
	                    		}
	                    		prime = prime * temp;

	                    	}
	                    	ans = ans/val;
	                    	return ans;
	                    }
	                    void sieveOfEratosthenes(int n)
	                    {
	                        // Create a boolean array "prime[0..n]" and initialize
	                        // all entries it as true. A value in prime[i] will
	                        // finally be false if i is Not a prime, else true.
	                        boolean prime[] = new boolean[n+1];
	                        for(int i=0;i<n;i++)
	                            prime[i] = true;

	                        for(int p = 2; p*p <=n; p++)
	                        {
	                            // If prime[p] is not changed, then it is a prime
	                            if(prime[p] == true)
	                            {
	                                // Update all multiples of p
	                                for(int i = p*p; i <= n; i += p)
	                                    prime[i] = false;
	                            }
	                        }

	                        // Print all prime numbers
	                        for(long i = 2; i <= n; i++)
	                        {
	                            if(prime[(int)i] == true)
	                                prim.add(i);
	                        }
	                    }

	                    static long power(long a,long b,long mod) {
                            long ans = 1;
                            a = a % mod;
                            while(b != 0) {
                                if(b % 2 == 1) {
                                    ans = (ans * a) % mod;
                                }
                                a = (a * a) % mod;
                                b = b/2;
                            }
                            return ans;
                        }
	                    class Pair implements Comparable<Pair>{
	                        int a;
	                        int b;
	                        int c;
	                        Pair(int a,int b,int c){
	                            this.b = b;
	                            this.a = a;
	                            this.c = c;
	                        }
	                        public boolean equals(Object o) {
	                            Pair p = (Pair)o;
	                            return this.a == p.a && this.b == this.b;
	                        }
	                        public int hashCode(){
	                            return Long.hashCode(a)*27 + Long.hashCode(b)*31;
	                        }
	                        public int compareTo(Pair p) {
	                        	if(this.a == p.a) {
	                        		return Long.compare(p.b, this.b);
	                        	}
	                            return Long.compare(this.a,p.a);
	                        }
	                    }

	                }

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author Anirudha
 */
public class JavaApplication47 {

   static  long max=1;
    static long max2=1;
    static long b;
    static long div=0;
    static long arr[]= new long[12345678];
    static long lst=1;
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        long x=sc.nextLong();
        primeFactors(x);
        //System.out.println(max+" "+max2+" "+b+" "+div );

        long c=b;
        long ans=Long.MAX_VALUE;
        for(int i=0;i<1234567;i++){
            if(arr[(int)i]==0)
                continue;
            b=i;
            long n1=n;
            long zero=0;
            while(n1!=0){
                   zero=zero+n1/b;
                   n1/=b;
            }
            long aa = zero/arr[(int)i];
            ans=Math.min(ans,aa);
//            System.out.println(i+"----"+aa+"----"+ans+" "+arr[i]);
        }
        if(lst!=1){
        b=lst;
        long n1=n;
            long zero=0;
            while(n1!=0){
                   zero=zero+n1/b;
                   n1/=b;
            }
            long aa = zero;
            ans=Math.min(ans,aa);}
//          }
        System.out.println(ans);
}

     public static void primeFactors(long n)
    {
        long tempdiv=0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            div++;
            max=max*2;
           // System.out.print(2 + " ");
            n /= 2;
//            System.out.println(2);
        }
        b=2;
        arr[2]=div;
//        System.out.println(max+" "+max2+" "+b+" "+div );

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
             max2=1;
             tempdiv=0;
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                tempdiv++;
                max2=max2*i;
             //   System.out.print(i + " ");
                n /= i;
//                System.out.println(i);
            }
            if(max<max2)
            {
                b=i;
                div=tempdiv;
                max=max2;
            }
            arr[i]=tempdiv;
        }

        if (n > 2)
        {
            if(n>max)
            {
                max=n;
                b=n;
                div=1;
            }
            lst=n;
//            System.out.println(n);
//            arr[(int)n]=1;
        }
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class HowmanyZerosandhowmanyDigits {
	static ArrayList<Integer> primes;
	static long b;
	//static double logB;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st;
		sieveLinear((int)1e6);
		long n;
		st = new StringTokenizer(br.readLine());
		n = Long.parseLong(st.nextToken());
		b = Long.parseLong(st.nextToken());
		HashMap<Long, Long> pfb = new HashMap<>();
		primefac(b, pfb);
		long p,t,pow,cnt;
		long zeros = Long.MAX_VALUE;
		for(Entry<Long, Long> e:pfb.entrySet()) {
			p = e.getKey();pow = e.getValue();
			t = p;
			cnt = 0;
			while(t<=n) {
				cnt += n/t;
				if(n/p < t)
					break;
				t*=p;
			}
			zeros = Math.min(zeros, cnt/pow);
		}
		out.println(zeros);
		out.flush();
	}
	static void primefac(long n, HashMap<Long, Long> hm){
		int i = 0;
		long p;
		while(n>1 && i<primes.size()) {
			p = primes.get(i++);
			long cnt = 0;
			while(n%p == 0) {
				cnt++;
				n/=p;
			}
			if(cnt > 0)
				hm.put(p, cnt);
		}
		if(n > 1)
			hm.put(n, 1l);
	}
	static void sieveLinear(int N)
	{
		primes = new ArrayList<Integer>();
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}
}

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

public class E {

	static StringBuilder st = new StringBuilder();

	static ArrayList<Long> primes;
	static int[] isComposite;

	static void sieve(int N) {
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1;
		primes = new ArrayList<Long>();

		for (int i = 2; i <= N; ++i)
			if (isComposite[i] == 0) {
				primes.add(i*1l);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)
						isComposite[j] = 1;
			}
	}

	static HashMap<Long, Integer> primeFactors(long N) {
		HashMap<Long, Integer> factors = new HashMap<>();
		int idx = 0;
		long p = primes.get(idx);

		while (p * p <= N)
		{
			int cnt = 0;
			while (N % p == 0)
			{
				N /= p;
				cnt++;
			}
			if (cnt > 0)
				factors.put(p, cnt);

			p = primes.get(++idx);
		}
		if (N != 1)
			factors.put(N, 1);
		return factors;
	}

	static long fact_pow(long n, long k )
	{
		long res = 0;
		while (n > 0)
		{
			n /= k;
			res += n;
		}
		return res;
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		sieve((int) 1e7);

		long n = sc.nextLong(), b = sc.nextLong();

		HashMap<Long, Integer> factors = primeFactors(b);

		long ans = (1l << 63) - 1;

		for (long x : factors.keySet())
				ans = Math.min(ans , fact_pow(n, x) / factors.get(x));

		out.println(ans);
		out.flush();
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

	}

	static void shuffle(int[] a) {
		int n = a.length;
		for (int i = 0; i < n; i++) {
			int r = i + (int) (Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}

}

//package codeForcesPractice;

import java.util.Scanner;
import java.util.Stack;

public class trailingLoves {

	public static void main(String[] args) {
		long ans = Long.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long b = sc.nextLong();
		long tempB = b;
		Stack<Long> factors = new Stack<Long>();
		long i = 2;
		while (i*i <= tempB) {
			if (tempB % i == 0) {
				tempB /= i;
				factors.push(i);
			} else {
				i++;
			}
		}
		if(tempB!=1) {
			factors.push(tempB);
		}
		while (!factors.isEmpty()) {
			long count = 1;
			long temp = factors.pop();
			while (!factors.isEmpty()) {
				long temp1 = factors.peek();
				if (temp1 != temp) {
					break;
				} else {
					count++;
					factors.pop();
				}
			}
			long anCount = 0;
			long adder = n / temp;
			i = 1;
			while (adder != 0) {
				anCount += adder;
				i++;
				adder = n / (long) Math.pow(temp, i);
			}

			ans = Long.min(ans, anCount / count);
		}
		sc.close();
		System.out.println(ans);
	}
}

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

			public class codeforces
			{
				public static void main(String[] args)
				{
					InputReader in = new InputReader(System.in);
					PrintWriter pw = new PrintWriter(System.out);

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

					HashMap<Long, Integer> map = primeFactorization(b);

					long ans = 0, min = Long.MAX_VALUE;

					for(long key : map.keySet())
					{
						ans = fun(key, n);
						ans /= map.get(key);

						min = Math.min(min, ans);
					}
					pw.println(min);

					pw.flush();
					pw.close();
				}

				public static long fun(long key, long n)
				{
					long ans = 0, k = key, M = 1000000000000000000L;

					while(key <= n && key > 0)
					{
						ans += n/key;

						if(M/key < k)
							break;

						key *= k;
					}

					return ans;
				}

				public static HashMap<Long, Integer> primeFactorization(long n)
				{
					HashMap<Long, Integer> map = new HashMap<>();

					for(long i=2;i*i<=n;i++)
					{
						while(n%i==0)
						{
							if(!map.containsKey(i))
								map.put(i, 1);
							else
								map.put(i, map.get(i)+1);

							n/=i;
						}
					}
					if(n!=1)
					{
						if(!map.containsKey(n))
							map.put(n, 1);
						else
							map.put(n, map.get(n)+1);
					}

					return map;
				}
				public static int BinarySearch_l(long[] a, long k)
				{
					int n = a.length;
					int i = 0, j = n-1;
					int mid = 0;

					if(k - a[n-1] > 0)
						return n;
					else
					{
						while(j - i > 0)
						{
							mid = (i+j)/2;

							if(k - a[mid] > 0)
								i = mid + 1;
							else
								j = mid;
						}
					}

					return i;
				}

				public static int BinarySearch_r(long[] a, long k)
				{
					int n = a.length;
					int i = 0, j = n-1;
					int mid = 0;

					if(k - a[0] < 0)
						return -1;
					else
					{
						while(j - i > 0)
						{
							mid = (int)Math.ceil((double)(i+j)/2);

							if(k - a[mid] >= 0)
								i = mid;
							else
								j = mid - 1;
						}
					}

					return i;
				}
				public static long fact(long n, long M)
				{
					long ans = 1;

					for(long i=n;i>0;i--)
					{
						ans = (ans*i)%M;
					}

					return ans;
				}

			/*	public static void DFS(int sourse)
				{
					int count = 0;
					visited[sourse] = true;

					for(int u : adj[sourse])
					{
						if(!visited[u])
						{
							DFS(u);
						}
					}

				}*/

				public static ArrayList Divisors(int n)
				{
				    ArrayList<Integer> div = new ArrayList<>();

				    for (int i=1; i<=Math.sqrt(n); i++)
				    {
				        if (n%i == 0)
				        {
				        	div.add(i);

				            if(n/i != i)
				            	div.add(n/i);
				        }
				    }
				    return div;
				}

				public static long GCD(long a,long b)
				{
					if(b==0)
						return a;
					else
						return GCD(b,a%b);
				}

				public static long LCM(long a,long b)
				{
					return (a*b)/GCD(a, b);
				}

				static class pair implements Comparable<pair>
				{
					Integer x, y;
					pair(int x,int y)
					{
						this.x=x;
						this.y=y;
					}

					public int compareTo(pair o) {
						int result = x.compareTo(o.x);
						if(result==0)
							result = y.compareTo(o.y);

						return result;
					}

					public String toString()
					{
						return x+" "+y;
					}

					public boolean equals(Object o)
					{
						if (o instanceof pair)
					    {
							pair p = (pair)o;
							return p.x - x == 0 && p.y - y == 0 ;
						}
						return false;
					}

					public int hashCode()
					{
						return new Long(x).hashCode()*31 + new Long(y).hashCode();
					}
				}

				static class InputReader
				{

					private final InputStream stream;
					private final byte[] buf = new byte[8192];
					private int curChar, snumChars;
					private SpaceCharFilter filter;

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

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

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

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

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

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

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

					public boolean isSpaceChar(int c)
					{
						if (filter != null)
							return filter.isSpaceChar(c);
						return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
					}

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

					public interface SpaceCharFilter
				    {
						public boolean isSpaceChar(int ch);
					}
				}

				static class CodeX {
		        public static void sort(long arr[]) {
		            merge_sort(arr, 0, arr.length - 1);
		        }

		        private static void merge_sort(long A[], long start, long end) {
		            if (start < end) {
		                long mid = (start + end) / 2;
		                merge_sort(A, start, mid);
		                merge_sort(A, mid + 1, end);
		                merge(A, start, mid, end);
		            }

		        }

		        private static void merge(long A[], long start,long mid, long end) {
		            long p = start, q = mid + 1;
		            long Arr[] = new long[(int)(end - start + 1)];
		            long k = 0;

		            for (int i = (int)start; i <= end; i++) {
		                if (p > mid)
		                    Arr[(int)k++] = A[(int)q++];

		                else if (q > end)
		                    Arr[(int)k++] = A[(int)p++];

		                else if (A[(int)p] < A[(int)q])
		                    Arr[(int)k++] = A[(int)p++];

		                else
		                    Arr[(int)k++] = A[(int)q++];
		            }
		            for (int i = 0; i < k; i++) {
		                A[(int)start++] = Arr[i];
		            }

		        }

		    }
			}

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

public class Test10 {

    Random rnd = new Random();
    PrintWriter pw = new PrintWriter(System.out);
    int a;

    void run(){
        long a = nl(), min = Long.MAX_VALUE, k=0;
        HashMap<Long, Long> h = getAllDiffNumbAndTheirQuantity(f(nl()));
        for(Map.Entry<Long, Long> p : h.entrySet()){
            k=0;
            for(long q=p.getKey(); q<=a; q*=p.getKey()){
                k+=a/q;
                if(q>a/p.getKey()) break;
            }
            min = Math.min(min, k/p.getValue());
        }
        pw.print(min);
        pw.flush();
    }

    ArrayList<Long> f(long a){
        ArrayList<Long> l = new ArrayList<>();
        for(long q=2; q*q<=a && q<4; q++) if(a%q==0) for(; a%q<1;) {a/=q; l.add(q);}
        for(long d=6, i=a; (d-1)*(d-1)<=i; d+=6){
            if(a%(d-1)<1)for(; a%(d-1)<1; ) {a/=(d-1); l.add(d-1);}
            if(a%(d+1)<1)for(; a%(d+1)<1; ) {a/=(d+1); l.add(d+1);}
        }
        if(a>1) l.add(a);
        return l;
    }

    HashMap<Long, Long> getAllDiffNumbAndTheirQuantity(ArrayList<Long> l){
        HashMap<Long,Long> ans = new HashMap<>();
        for(long i : l) ans.put(i, ans.getOrDefault(i, 0L)+1);
        return ans;
    }

    static class PyraSort {

        private static int heapSize;

        public static void sort(int[] a) {
            buildHeap(a);
            while (heapSize > 1) {
                swap(a, 0, heapSize - 1);
                heapSize--;
                heapify(a, 0);
            }
        }

        private static void buildHeap(int[] a) {
            heapSize = a.length;
            for (int i = a.length / 2; i >= 0; i--) {
                heapify(a, i);
            }
        }

        private static void heapify(int[] a, int i) {
            int l = 2 * i + 2;
            int r = 2 * i + 1;
            int largest = i;
            if (l < heapSize && a[i] < a[l]) {
                largest = l;
            }
            if (r < heapSize && a[largest] < a[r]) {
                largest = r;
            }
            if (i != largest) {
                swap(a, i, largest);
                heapify(a, largest);
            }
        }

        private static void swap(int[] a, int i, int j) {
            a[i] ^= a[j] ^= a[i];
            a[j] ^= a[i];
        }
    }

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

    InputStream is = System.in;
    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 nline(){
        int b = readByte();
        StringBuilder sb = new StringBuilder();
        while (b!=10) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(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 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();
        }
    }
}

import java.util.Scanner;

public class hgg {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long del = 2;
        long n = in.nextLong();
        long b = in.nextLong();
        long a[] = new long[100];
        long c[] = new long[100];
        int r = 0;
        while (b > 1 && del * del <= b) {
            if (b % del == 0) {
                b /= del;

                if (r == 0) {
                    a[r] = del;
                    c[r] = 1;
                    r++;
                } else {
                    if (del != a[r - 1]) {
                        a[r] = del;
                        c[r] = 1;
                        r++;
                    } else {
                        c[r - 1]++;
                    }
                }
            } else {
                del++;
            }
        }
        if (b > 1) {
            if (r == 0) {
                a[r] = b;
                c[r] = 1;
                r++;
            } else {
                if (b != a[r - 1]) {
                    a[r] = b;
                    c[r] = 1;
                    r++;
                } else {
                    c[r - 1]++;
                }
            }
        }

        long mn = func(n, a[0]) / c[0];
        for (int i = 1; i < r; i++) {
            long res = func(n, a[i]) / c[i];
            mn = Math.min(mn, res);
        }
        System.out.println(mn);

    }

    public static long func(long n, long l) {
        long ans = 0;
        while (n >= l) {
            n /= l;
            ans += n;
        }
        return ans;
    }
}

import java.util.*;
public class C {
    public static void main(String args[])throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        Map<Long, Long> hm = new HashMap<>();
        for (long i = 2l; i * i <= b; i++) {
            long cnt = 0l;
            while (b % i == 0) {
                cnt ++;
                b /= i;
            }
            if (cnt > 0l)
            hm.put(i, cnt);
        }
        if (b > 1)
        hm.put(b, 1l);
        long pow = Long.MAX_VALUE;
        for (Map.Entry<Long, Long> entry : hm.entrySet()) {
            long p = 0;
            for (long j = entry.getKey();;) {
                p += n / j;
                if (j <= n / entry.getKey()) j *= entry.getKey();
                else break;
            }
            p /= entry.getValue();
            if (p < pow)
            pow = p;
        }
        System.out.print(pow);
    }
}

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

public class C {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    private static class Solver {

        private long f(long n, long x) {
            if (n < x) return 0;
            return n / x + f(n / x, x);
        }

        private long min(long a, long b) {
            return a > b ? b : a;
        }

        private void solve(InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();

            long ans = Long.MAX_VALUE;
            for (long i = 2; i * i <= b; i++) {
                if (b % i != 0) continue;
                int j = 0;
                while (b % i == 0) {
                    b /= i;
                    j++;
                }
                ans = min(ans, f(n, i) / j);
            }
            if (b > 1) ans = min(ans, f(n, b));

            out.println(ans);
        }
    }

    private static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

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

import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String s1[]=br.readLine().split(" ");
            long n=Long.parseLong(s1[0]);
            long b=Long.parseLong(s1[1]);
            long b1=b;

            ArrayList<Long> al=new ArrayList<Long>();
            if(b1%2==0)
            {
                  al.add(2l);
               while(b1%2==0)
                b1=b1/2;
            }

            for(int i=3;i<=(int)Math.sqrt(b);i++)
            {
               if(b1%i==0)
            {
                  al.add((long)i);
               while(b1%i==0)
                b1=b1/i;
            }
            }

            if(b1>2)
             al.add(b1);

            int m=al.size();   b1=b;   long min=Long.MAX_VALUE;
             for(int i=0;i<m;i++)
            {
                  long c1=0,c2=0;   long n1=n;
                  long r=(long)al.get(i);
                  while(b1%r==0)
                  { c1++;  b1=b1/r; }
                  while(n1>=r)
                  { c2+=n1/r;  n1=n1/r; }
                  min=Math.min(min,c2/c1);
            }
            System.out.println(min);
      }
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        private static final long INFLL = (long) 9e18 + 7;
        boolean[] isPrime = new boolean[(int) 1e6 + 10];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            sieve();
            long ans = INFLL;
            for (int i = 2; (long) i * i <= b; i++) {
                if (b % i == 0 && isPrime[i]) {
                    long total = 0;
                    long cur = i;
                    while (cur <= n) {
                        total += n / cur;
                        if (cur > n / i) break;
                        cur *= i;
                    }
                    int cnt = 0;
                    while (b % i == 0) {
                        b /= i;
                        cnt++;
                    }
                    ans = MaxMin.Min(ans, total / cnt);
                }
            }

            if (b != 1) {
                long total = 0;
                long cur = b;
                while (cur <= n) {
                    total += n / cur;
                    if (cur > n / b) break;
                    cur *= b;
                }
                ans = MaxMin.Min(ans, total);
            }

            out.println(ans);
        }

        private void sieve() {
            for (int i = 1; i <= (int) 1e6 + 5; i++) isPrime[i] = true;
            isPrime[0] = false;
            isPrime[1] = false;
            for (int i = 2; i <= (int) 1e6 + 5; i++)
                if (isPrime[i])
                    for (long j = (long) i * i; j <= (long) 1e6 + 5; j += i)
                        if (j < (long) 1e6 + 5)
                            isPrime[(int) j] = false;
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Min(T x, T y) {
            T min = x;
            if (y.compareTo(min) < 0) min = y;
            return min;
        }

    }

    static class InputReader extends InputStream {
        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 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;
        }

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

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.util.Collections;
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();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            TreeMap<Long, Integer> bpDivs = divs(b);
            ArrayList<Long> bpDivCnt = new ArrayList<>();
            BigInteger bigN = BigInteger.valueOf(n);
            for (long curDiv : bpDivs.keySet()) {
                long cnt = bpDivs.get(curDiv);
                long curDivCnt = 0;
                BigInteger curDivBig = BigInteger.valueOf(curDiv);
                for (BigInteger pow = BigInteger.valueOf(curDiv); pow.compareTo(bigN) <= 0; pow = pow.multiply(curDivBig)) {
                    curDivCnt += bigN.divide(pow).longValue();
                }
                bpDivCnt.add(curDivCnt / cnt);
            }
            out.println(Collections.min(bpDivCnt));
        }

        TreeMap<Long, Integer> divs(long a) {
            TreeMap<Long, Integer> res = new TreeMap<>();
            long cur = a;
            for (long div = 2; div * div <= a; div++) {
                while (cur % div == 0) {
                    cur /= div;
                    res.put(div, res.getOrDefault(div, 0) + 1);
                }
            }
            if (cur > 1) {
                res.put(cur, res.getOrDefault(cur, 0) + 1);
            }
            return res;
        }

    }

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

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

    }
}

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

// author @mdazmat9
public  class codeforces{
    static LinkedHashSet<Long> set=new LinkedHashSet<Long>();
    static  HashMap<Long,Long> map=new HashMap();
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int test = 1;
        for (int ind = 0; ind < test; ind++) {
                long n=sc.nextLong();
                long b=sc.nextLong();
                long m=-1;
                long p=-1;
                primeFactors(b);
                ArrayList<Long> ans=new ArrayList<>();
             //   out.println(set);
            Iterator it = set.iterator();
            while (it.hasNext()){
                long a=(long)it.next();
              //  out.println(a);
               long power=map.get(a);
                long sum=0;
                long raise=1;
                long check=-1;
                while (check!=0){
                    check=(long)(n/(long)Math.pow(a,raise));
                    raise++;
                    sum+=check;
                }
                ans.add(sum/power);
            }

        Collections.sort(ans);
          //  out.println(ans);
    out.println(ans.get(0));

        }
        out.flush();
    }

    public static void primeFactors(long n)
    {
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            if(map.containsKey(2l)){
                map.put(2l,map.get(2l)+1);
            }
            else{
                map.put(2l,1l);
            }
            set.add(2l);
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                if(map.containsKey(i)){
                    map.put(i,map.get(i)+1l);
                }
                else{
                    map.put(i,1l);
                }
                set.add(i);
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2) {
            set.add(n);
            if(map.containsKey(n)){
                map.put(n,map.get(n)+1);
            }
            else{
                map.put(n,1l);
            }
        }
    }

    static   void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    static long gcd(long a , long b)
    {
        if(b == 0)
            return a;
        return gcd(b , a % b);
    }

}
class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;

    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }

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

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

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

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

class OutputWriter {
    BufferedWriter writer;

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

    public void print(int i) throws IOException {
        writer.write(i);
    }

    public void print(String s) throws IOException {
        writer.write(s);
    }

    public void print(char[] c) throws IOException {
        writer.write(c);
    }

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

}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= b; i++){
            if(1L * i * i > b){
                i = b;
            }
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    if((double) mul * i >= (double) n){
                        break;
                    }
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        return res;
    }
}

import java.util.*;

public class C
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong(), b = in.nextLong();
        // long b = (long)1e12;
        ArrayList<Long> P = gen(b+1);
        // System.out.println(P.size());
        HashMap<Long, Long> fac = new HashMap<>();
        for (long p : P)
        {
            if (b %p == 0)
            {
                long cnt = 0;
                while (b %p == 0)
                {
                    b /= p;
                    cnt++;
                }
                fac.put(p, cnt);
            }
        }
        if (b != 1L) fac.put(b, 1L);

        long min = (long)1e19;
        for (long p : fac.keySet())
        {
            long m = n, cnt = 0;
            while (m > 0)
            {
                // System.out.println("("+p+", "+m+")");
                cnt += (m /= p);
            }
            // System.out.println(cnt+" --> "+(cnt/fac.get(p)));
            min = Math.min(min, cnt/fac.get(p));
        }

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

    public static ArrayList<Long> gen(long b)
    {
        ArrayList<Long> res = new ArrayList<>();
        res.add(2L);
        boolean[] v = new boolean[(int)Math.sqrt(b)+1];
        for (long i = 3; i*i <= b; i += 2L)
            if (!v[(int)i])
                for (long j = i+i; j*j <= b; j += i)
                    v[(int)j] = true;
        for (long i = 3; i*i <= b; i += 2L)
            if (!v[(int)i])
                res.add(i);
        return res;
    }
}

import java.util.*;
public class C1114 {

     HashMap<Long, Integer> primeFactors(long n) {
        // Print the number of 2s that divide n
        HashMap<Long, Integer> primes = new HashMap<>();
        while (n%2==0)
        {
            Integer val = primes.get(new Long(2));
            primes.put(new Long(2), (val != null? ++val : 1));
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (Integer i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                Integer val = primes.get(new Long(i));
                //System.out.println(val + " " + i);
                val = ((val != null) ? ++val : 1);
                //System.out.println(val + " " + i);
                primes.put(new Long(i), val);
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)
            primes.put(new Long(n), 1);
        return primes;
    }
    Long expFactor(Long n, Long p)
    {
        Long x = p;
        Long exponent = new Long(0);
        while ((n/x) > 0)
        {
            //System.out.println(n/x);
            exponent += n/x;
            x = Long.MAX_VALUE/x > p ? x*p: Long.MAX_VALUE;
        }
        return exponent;
    }
    void solve() {
        Scanner s = new Scanner(System.in);
        long n, b;
        n = s.nextLong();
        b = s.nextLong();
        Long ans = Long.MAX_VALUE;
        HashMap<Long, Integer> primes_b = primeFactors(b);
        //System.out.println(primes_b);
        for (Map.Entry<Long, Integer> i: primes_b.entrySet()) {
            Long temp = i.getKey();
            Long exponent = expFactor(n, temp);
            //System.out.println(temp+ " " + exponent);
            ans = Math.min(ans, exponent/i.getValue());
        }
        System.out.println(ans);
    }

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

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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static int[] dp;
    static ArrayList<Integer>[] adj;
    static boolean[] visit;
    static int[] arr;
    static long ceildiv(long x, long y) { return (x + y - 1) / y; }
    static int mod(long x, int m) { return (int) ((x % m + m) % m); }
    public static long gcd(long x, long y) {return y == 0 ? x : gcd(y, x % y);}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        long n=sc.nextLong(), b=sc.nextLong();
        HashMap<Long, Integer> prime=new HashMap<Long, Integer>();
        for(int i=2; i<=b/i; i++){
            if(b%i==0){
                int pow=0;
                while(b%i==0){
                    pow++;
                    b/=i;
                }
                prime.put(i*1l, pow);
            }
        }
        if(b!=1)
            prime.put(b, 1);
        HashMap<Long, Long> ans=new HashMap<Long, Long>();
        for(Map.Entry<Long, Integer> ent: prime.entrySet())
            ans.put(ent.getKey(), num(n, ent.getKey())/ent.getValue());
        long res=Long.MAX_VALUE;
        for(long x: ans.values())
            res=Math.min(x, res);
        pw.println(res);
        pw.close();
    }
    static long num(long n, long b){
        long ans=0;
        long temp=b;
        while(temp<=n){
            ans+=n/temp;
            if(((long)2e18)/temp>b)
                temp*=b;
            else
                break;
        }
        return ans;
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]);
        pw.println();
    }
    static void printArr(ArrayList list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i) + " ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        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 long nextLong() throws IOException {
            return Long.parseLong(next());
        }

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

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        long x;
        long y;
        public Pair(long x, long y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (int)(this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            return (int)(this.x-p.x);
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
        public Pair multiply(int x){
            return new Pair(x*this.x, x*this.y);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
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();
    }

    static class TaskC {
        static boolean[] prime;

        void sieveOfEratosthenes(int n) {
            // Create a boolean array "prime[0..n]" and initialize
            // all entries it as true. A value in prime[i] will
            // finally be false if i is Not a prime, else true.
            for (int i = 0; i < n; i++)
                prime[i] = true;
            prime[1] = false;
            for (int p = 2; p * p <= n; p++) {
                // If prime[p] is not changed, then it is a prime
                if (prime[p] == true) {
                    // Update all multiples of p
                    for (int i = p * p; i <= n; i += p)
                        prime[i] = false;
                }
            }

        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long b = in.nextLong();
            prime = new boolean[(int) (Math.sqrt(b) + 10)];
            sieveOfEratosthenes(prime.length - 1);
            long total = countTotal(N, b);
            HashSet<Long> primesFactors = primeFactors(b);
            ArrayList<Long> primes = new ArrayList<>();
            ArrayList<Long> cnt = new ArrayList<>();
            for (long i : primesFactors) {
                long tempN = b;
                long val = 0;
                while (tempN % i == 0) {
                    val++;
                    tempN /= i;
                }
                cnt.add(val);
                primes.add((long) i);
            }
            if (primes.size() == 0) {
                primes.add(b);
                cnt.add(1L);
            }
            long min = Long.MAX_VALUE;
            for (int i = 0; i < primes.size(); i++) {
                min = Math.min(min, countTotal(N, primes.get(i)) / (cnt.get(i)));
            }
            out.println(min);
        }

        static HashSet<Long> primeFactors(long n) {
            HashSet<Long> res = new HashSet<>();
            while (n % 2 == 0) {
                res.add((long) (2));
                n /= 2;
            }
            for (int i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    res.add((long) (i));
                    n /= i;
                }
            }

            // This condition is to handle the case whien
            // n is a prime number greater than 2
            if (n > 2)
                res.add((long) n);
            return res;
        }

        static long countTotal(long n, long val) {
            long power = val;
            long cnt = 0;
            while (power <= n) {
                cnt += n / power;
                if (n / val < power) {
                    return cnt;
                }
                power *= val;
            }
            return cnt;
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import static java.lang.Long.MAX_VALUE;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.math.BigInteger.valueOf;
import static java.nio.charset.StandardCharsets.UTF_8;

public class Main {

    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in, UTF_8));
             BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, UTF_8))) {
            StringTokenizer tokens = new StringTokenizer(in.readLine());
            long n = parseLong(tokens.nextToken());
            long b = parseLong(tokens.nextToken());
            List<long[]> divs = findDivs(b);
            long ans = MAX_VALUE;
            for (long[] div : divs) {
                long p = div[0];
                long deg = div[1];
                long s = p;
                long total = 0;
                while (n / s > 0) {
                    total += n / s;
                    if (n / s < p) {
                        break;
                    }
                    s *= p;
                }
                ans = min(total / deg, ans);
            }
            out.write(ans + "");
            out.newLine();
        }
    }

    private static List<long[]> findDivs(long b) {
        List<long[]> divs = new ArrayList<>();
        if (valueOf(b).isProbablePrime(100)) {
            divs.add(new long[]{b, 1});
            return divs;
        }
        for (long i = 2; i <= b; i++) {
            if (b % i == 0) {
                int deg = 0;
                while (b % i == 0) {
                    deg++;
                    b /= i;
                }
                divs.add(new long[]{i, deg});
                if (valueOf(b).isProbablePrime(100)) {
                    divs.add(new long[]{b, 1});
                    return divs;
                }
            }
        }
        return divs;
    }
}

import java.util.*;
import java.io.*;
public class Main {
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        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 long nextLong() throws IOException {
            return Long.parseLong(next());
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong(),b=sc.nextLong();
      long ans=Long.MAX_VALUE;
      for(long i=2;i<=b;i++){
        if(i*i>b)i=b;
        long cnt=0;
        while(b%i==0){b/=i;cnt++;}
        if(cnt>0){
          long m=1,tmp=0;
          while(m<=(n/i)){m*=i;tmp+=n/m;}
          ans=Math.min(ans,(tmp/cnt));
        }
      }
      System.out.print(ans);
    }
}

//package test;

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

public class CF1 {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader s = new FastReader();
		long n = s.nextLong();
		long b = s.nextLong();
		ArrayList<Long> al = new ArrayList<>();
		ArrayList<Long> freq = new ArrayList<>();
		long temp = b;
		for(int i=2;((long)i*(long)i)<=temp;i++)
		{
			if(temp%i==0)
			{
				al.add((long)i);
				int f = 0;
				while(temp%i==0)
				{
					temp = temp/i;
					f++;
				}
				freq.add((long)f);
			}
		}
		if(temp>1)
		{
			al.add(temp);
			freq.add((long)1);
		}
		if(al.size()==0)
		{
			al.add(b);
			freq.add((long)1);
		}
		ArrayList<Long> acfreq = new ArrayList<>();
		for(int i=0;i<al.size();i++)
		{
			long e = al.get(i), f = 0, cn = n;
			while(e<=cn)
			{
				f += cn/e;
				cn = cn/e;
			}
			acfreq.add(f);
		}
		long ans = Long.MAX_VALUE;
		for(int i=0;i<al.size();i++)
		{
			//System.out.println(al.get(i)+" "+freq.get(i)+" "+acfreq.get(i));
			ans = Math.min(ans, acfreq.get(i)/freq.get(i));
			//System.out.println(ans);
		}
		System.out.println(ans);
	}

	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;
        }
    }

}

//package codeforces.D538;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

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

        String[] input = br.readLine().split(" ");

        long n = Long.parseLong(input[0]);
        long base = Long.parseLong(input[1]);

        long zeroCount = Long.MAX_VALUE;

        Map<Long, Long> primeFactorsFrequencyMap = getPrimeFactorFrequencyMap(base);

        for (Map.Entry<Long, Long> entry : primeFactorsFrequencyMap.entrySet()) {
            long p = entry.getKey();
            long c = entry.getValue();

            long count = 0;
            long k = n;

            while (k / p > 0) {
                count += k / p;
                k /= p;
            }

            zeroCount = Math.min(zeroCount, count / c);
        }

        System.out.println(zeroCount);
    }

    private static Map<Long, Long> getPrimeFactorFrequencyMap(long base) {
        Map<Long, Long> primeFactorFrequencyMap = new HashMap<>();

        long twoCount = 0;

        while (base % 2 == 0) {
            base /= 2;
            twoCount++;
        }

        if (twoCount > 0) {
            primeFactorFrequencyMap.put(2L, twoCount);
        }

        for (int i = 3; i <= Math.sqrt(base); i += 2) {
            long count = 0;

            while (base % i == 0) {
                base /= i;
                count++;
            }

            if (count > 0) {
                primeFactorFrequencyMap.put((long) i, count);
            }
        }

        if (base > 2) {
            primeFactorFrequencyMap.put(base, 1L);
        }

        return primeFactorFrequencyMap;
    }
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class TrailingZeroes{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();

        List<Long> factors = new ArrayList<>();
        Map<Long, Long> factMult = new HashMap<>();

        for (long i = 2; i * i <= b; i++) {
            if (b % i == 0) {
                factors.add(i);
                long count = 0;
                while (b % i == 0) {
                    count++;
                    b = b / i;
                }
                factMult.put(i, count);
            }
        }

        if (b > 1) {
            factors.add(b);
            factMult.put(b, 1L);
        }
        long counter = Long.MAX_VALUE;
        for (long l : factors) {
            long temp = n;
            long times = 0;
            while (temp > 0) {
                times += temp / l;
                temp /= l;
            }
            counter = Math.min(counter, times / factMult.get(l));
        }

        System.out.println(counter);
    }

}

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

public class Main {
    static final int UNCALC = -1;
    static final int INF = (int) 1e9;
    static int max = (int) 1e7;
    static ArrayList<Integer> primes;
    static int[] isComposite;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long n = sc.nextLong();
        long b = sc.nextLong();
        sieve(max);
        ArrayList<Pair> pf = primeFactors(b);
        long max = -1;
        for (Pair x : pf) {
            long ans = getPow(n, x.p);
            if (max == -1) max = ans / x.e;
            else
                max = Math.min(ans / x.e, max);
        }
        out.println(max);
        out.flush();
        out.close();
    }

    static void sieve(int N) {
        isComposite = new int[N + 1];
        isComposite[0] = isComposite[1] = 1;
        primes = new ArrayList<Integer>();
        for (int i = 2; i <= N; ++i)
            if (isComposite[i] == 0) {
                primes.add(i);
                if (1l * i * i <= N)
                    for (int j = i * i; j <= N; j += i)
                        isComposite[j] = 1;
            }
    }

    static ArrayList<Pair> primeFactors(long N) {
        ArrayList<Pair> factors = new ArrayList<Pair>();
        int idx = 0, p = primes.get(idx);
        while (1l * p * p <= N) {
            int e = 0;
            while (N % p == 0) {
                e++;
                N /= p;
            }
            if (e != 0) factors.add(new Pair(p, e));
            p = primes.get(++idx);
        }

        if (N != 1)
            factors.add(new Pair(N, 1));
        return factors;
    }

    static long getPow(long n, long p) {
        long res = 0;
        while (n > 0) {
            res += n / p;
            n /= p;
        }
        return res;
    }

    static class Pair {
        long p;
        int e;

        public Pair(long p, int e) {
            this.p = p;
            this.e = e;
        }
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            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 IOException {
            return Integer.parseInt(next());
        }

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

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

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

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

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

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

    }
}

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

public class math {

	public static void main(String[] args) throws Exception {
		FastIO sc = new FastIO(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		long n = sc.nextLong();
		long b = sc.nextLong();

		HashMap<Long, Long> divisors = primeFactorize(b);
		//System.out.println(divisors);

		long minDivisors = Long.MAX_VALUE;

		for(Long key : divisors.keySet()) {
			long count = countFactors(n, key);
			minDivisors = Math.min(minDivisors, count/divisors.get(key));
		}

		pw.println(minDivisors);
		pw.close();

	}

	static long countFactors(long n, long div) {
		long ret = 0;

		long test = div;
		while(test <= n) {
			ret += n/test;
			if(Long.MAX_VALUE/test >= div)
				test *= div;
			else break;
		}

		return ret;
	}

	static HashMap<Long, Long> primeFactorize(long a) {
		HashMap<Long, Long> ret = new HashMap<Long, Long>();
		for(long x = 2; x <= Math.sqrt(a); x++) {
			while(a % x == 0) {
				ret.put(x, ret.getOrDefault(x, 0l)+1);
				a /= x;
			}
		}

		if(a > 1) ret.put(a, 1l);

		return ret;
	}

	static class FastIO {

		//Is your Fast I/O being bad?

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastIO(String fileName) throws Exception {
			dis = new FileInputStream(fileName);
		}

		public FastIO(InputStream is) throws Exception {
			dis = is;
		}

		int nextInt() throws Exception {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		long nextLong() throws Exception {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		byte nextByte() throws Exception {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String next() throws Exception {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}

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

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

		/**/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		/*/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/c.in"))));
		/**/

		long n = sc.nextLong();
		long b = sc.nextLong();

		boolean[] comp = new boolean[1000001];
		for (int i = 2; i <= 1000; i++) {
			if (comp[i])
				continue;
			for (int j = i*i; j <= 1000000; j+=i)
				comp[j] = true;
		}
		TreeMap<Long, Integer> powers = new TreeMap<Long, Integer>();
		for (int i = 2; i <= 1000000; i++) {
			if (comp[i])
				continue;
			if (b%i==0) {
				powers.put((long)i, 0);
				while (b%i==0) {
					powers.put((long)i, powers.get((long)i)+1);
					b /= i;
				}
			}
		}
		if (b != 1) {
			powers.put(b, 1);
		}
		long ans = Long.MAX_VALUE;
		for (long p : powers.keySet()) {
			long p2 = p;
			long val = 0;
			while (p2 <= n) {
				val += n/p2;
				if (n/p2<p)
				   break;
				p2 *= p;
			}
			ans = Math.min(ans, val/powers.get(p));
		}
		System.out.println(ans);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ACM {

    public static void main(String[] args) {
        List<Long> pris = new ArrayList<>();
        List<Integer> isPri = new ArrayList<>();
        int g = 2000010;
        for (int i = 0; i <= g; ++i) {
            isPri.add(-1);
        }
        for (int i = 2; i <= g; ++i) {
            if (isPri.get(i) == -1) {
                pris.add((long) i);
                for (int j = i; j <= g; j += i) {
                    isPri.set(j, 1);
                }
            }
        }
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long nowB = b;
        long dv = 1;
        long count = 0;
        long ans = Long.MAX_VALUE;

        for (int i = 0; i < pris.size() && pris.get(i) * pris.get(i) <= nowB; ++i) {
            long x = pris.get(i);
            if (nowB % x == 0) {
                dv = x;
                count = 0;
                while (nowB % x == 0) {
                    nowB /= x;
                    count++;
                }
                ans = Math.min(ans, cal(n, dv) / count);
            }
        }
        if (nowB > 1) {
            ans = Math.min(ans, cal(n, nowB));
        }
        System.out.println(ans);
    }

    private static long cal(long n, long d) {
        long result = 0;
        long nd = n;
        while (nd >= d) {
			nd = nd / d;
            result += nd;
        }
        return result;
    }
}

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

public class TrailingLoves {
	public static ArrayList<Long> primeFactorization(long n)
	{
		ArrayList<Long> factors = new ArrayList<Long>();
		for (long i = 2; i <= Math.sqrt(n); i++) {
			long count=0;
			while(n%i==0)
			{
				count++;n/=i;
			}
			if(count!=0){factors.add(i);factors.add(count);}
		}
		if(n!=1){factors.add(n);factors.add(1L);}
		return factors;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		long n = Long.parseLong(st.nextToken()); long b = Long.parseLong(st.nextToken());
		ArrayList<Long> bFac=primeFactorization(b);
		long minOcc=Long.MAX_VALUE;
		for (int i = 0; i < bFac.size(); i+=2) {
			long factor= bFac.get(i);
			long temp=n;
			int count=0;
			while(temp>=factor)
			{
				count++;
				temp/=factor;
			}
			long occurences=0;
			long product=factor;
			for (int j = 1; j <= count; j++) {
				occurences+=n/product;
				product*=factor;
			}
			minOcc= Math.min(minOcc, occurences/bFac.get(i+1));
		}
		pw.print(minOcc);
		pw.close();
	}
}

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

public class Main {

	static PrintWriter pw = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException, InterruptedException {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(), b = sc.nextLong();
		pair[] arr = factors(b);
		long c = chk(n, arr[0]);
		for (int i = 1; i < arr.length; i++) {
			c = Math.min(c, chk(n, arr[i]));
		}
		pw.println(c);
		pw.close();
	}

	static long chk(long n, pair p) {
		long c = 0, y = p.x;
		while (n / y > 0) {
			long tmp = y;
			c += n / y;
			y *= p.x;
			if (y / p.x != tmp)
				break;
		}
		return c / p.y;
	}

	static pair[] factors(long n) {
		ArrayList<pair> arrl = new ArrayList<>();
		long c = 0;
		while (n % 2 == 0) {
			n /= 2;
			c++;
		}
		if (c != 0) {
			arrl.add(new pair(2, c));
		}
		for (int i = 3; i <= Math.sqrt(n); i += 2) {
			c = 0;
			while (n % i == 0) {
				n /= i;
				c++;
			}
			if (c != 0) {
				arrl.add(new pair(i, c));
			}
		}
		if (n != 1) {
			arrl.add(new pair(n, 1));
		}
		pair[] arr = new pair[arrl.size()];
		int p = 0;
		for (pair k : arrl) {
			arr[p++] = k;
		}
		return arr;
	}

	static int countDivisors(int N) {
		int ans = 1;
		for (int p : primes) {
			if (p * p * p > N)
				break;
			int count = 1;
			while (N % p == 0) {
				N = N / p;
				count = count + 1;
			}
			ans = ans * count;
		}

		if (primes.contains(N))
			ans = ans * 2;
		else if (sp.contains((long) N))
			ans = ans * 3;
		else if (N != 1)
			ans = ans * 4;
		return ans;
	}

	static int divisors(int n) {
		int c = 0;
		for (int i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				if (n / i == i) {
					c++;
				} else {
					c += 2;
				}
			}
		}
		return c;
	}

	static long bs(int x, int[] arr) {
		int start = 0, end = arr.length - 1;
		long ans = -1;
		while (start <= end) {
			int mid = (start + end) / 2;
			if (arr[mid] == x) {
				ans = mid;
				end = mid - 1;
			} else if (arr[mid] > x) {
				end = mid - 1;
			} else {
				start = mid + 1;
			}
		}
		return ans;
	}

	static long pow(long a, long e) {
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

	static HashSet<Integer> getFactorization(int x) {
		HashSet<Integer> ret = new HashSet<>();
		while (x != 1) {
			ret.add(lp[x]);
			x = x / lp[x];
		}
		return ret;
	}

	static int[] lp;
	static TreeSet<Integer> primes;
	static TreeSet<Long> sp;

	static void sieveLinear(int N) {
		primes = new TreeSet<Integer>();
		lp = new int[N + 1]; // lp[i] = least prime divisor of i
		for (int i = 2; i <= N; ++i) {
			if (lp[i] == 0) {
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for (int p : primes)// all primes smaller than or equal my lowest prime divisor
				if (p > curLP || p * 1l * i > N)
					break;
				else
					lp[p * i] = p;
		}
	}

	static class pair implements Comparable<pair> {
		long x;
		long y;

		public pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public String toString() {
			return x + " " + y;
		}

		public boolean equals(Object o) {
			if (o instanceof pair) {
				pair p = (pair) o;
				return p.x == x && p.y == y;
			}
			return false;
		}

		public int hashCode() {
			return new Double(x).hashCode() * 31 + new Double(y).hashCode();
		}

		public int compareTo(pair other) {
			if (this.x == other.x) {
				return Long.compare(this.y, other.y);
			}
			return Long.compare(this.x, other.x);
		}
	}

	static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

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

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if (this.y == other.y)
					return this.z - other.z;
				return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		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 long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

		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);
		}

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

	}
}

import java.util.HashMap;
import java.util.Scanner;
public class C_TrailingLoves {

	public static void main(String[] args){
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long b=sc.nextLong();

		HashMap<Long,Integer> primefac = new HashMap<Long,Integer>();

		for(long i=2;i<=Math.sqrt(b);i++) {
			int cc=0;
			while(b%i==0) {
				b/=i;
				cc++;
			}
			if(cc>0){
				primefac.put(i,cc);
			}
		}
		if(b!=1) {
			primefac.put(b,primefac.containsKey(b)?primefac.get(b)+1:1);
		}

		//		for(long i:primefac.keySet()) {
		//			System.out.println(i+" "+primefac.get(i));
		//		}

		long cn[]=new long[primefac.size()];

		int idx=0;
		for(long j:primefac.keySet()) {
			long tmp=j;
			while(tmp<=n) {
//				System.out.println("n\ttmp\tn/tmp\t");
//				System.out.println(n+"\n"+tmp+"\n"+(n/tmp));
				cn[idx]+=n/tmp;
//				System.out.println(cn[idx]);
				try {
					tmp=Math.multiplyExact(tmp,j);
				}catch(Exception e){
					break;
				}
			}
			cn[idx++]/=primefac.get(j);
		}
		long min=Long.MAX_VALUE;

		for(int i=0;i<cn.length;i++) {
//			System.out.println(cn[i]+" ");
			min=Math.min(min, cn[i]);
		}

		//		boolean flag=true;
		//		while(flag) {
		//			int idx=0;
		//			for(long j:primefac.keySet()) {
		//				cn[idx]-=primefac.get(j);
		//				if(cn[idx]<=0) {
		//					flag=false;
		//				}
		//				idx++;
		//			}
		//			zeros++;
		//		}
		System.out.println(min);
		sc.close();
	}

}

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

public class c {
	long fpc(long n, long prime) {
		long res = 0;
		long primePower = prime;
		while(n / primePower > 0) {
			res += n / primePower;
			try { primePower = Math.multiplyExact(primePower, prime); }
			catch(Exception e) { return res; }
		}
		return res;
	}
	long f(long n, long b) {
		List<Long> primes = new ArrayList<>();
		List<Long> powers = new ArrayList<>();
		for(long prime = 2 ; prime * prime <= b ; prime++) {
			if(b % prime == 0) {
				long power = 0;
				while(b % prime == 0) {
					b /= prime;
					power++;
				}
				primes.add(prime);
				powers.add(power);
			}
		}
		if(b > 1) {
			primes.add(b);
			powers.add(1L);
		}
		long min = Long.MAX_VALUE;
		for(int i = 0 ; i < primes.size() ; i++)
			min = Math.min(min, fpc(n, primes.get(i)) / powers.get(i));
		if(min == Long.MAX_VALUE) min = 0;
		return min;
	}
	long correct(long n, int b) {
		int nf = 1;
		for(int i = 1 ; i <= n ; i++)
			nf *= i;
		String NF = Integer.toString(nf, b);
		int cnt = 0;
		for(int i = NF.length() - 1 ; i >= 0 ; i--) {
			if(NF.charAt(i) != '0') break;
			cnt++;
		}
		return cnt;
	}
	public c() {
		FS scan = new FS();
		long n = scan.nextLong(), b = scan.nextLong();
		System.out.println(f(n, b));
	}
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() {
			while(!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) { e.printStackTrace(); }
			}
			return st.nextToken();
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}
	public static void main(String[] args) { new c(); }
}

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

public class P1114C {

  private static void solve() {
    long n = nextLong();
    long b = nextLong();

    System.out.println(getAns(n, b));
  }

  private static long getAns(long n, long base) {
    long ans = Long.MAX_VALUE;
    for (long p = 2; p * p <= base; ++p) {
      if (base % p == 0) {
        int q = 0;
        while (base % p == 0) {
          q++;
          base /= p;
        }
        ans = Math.min(ans, getPow(n, p) / q);
      }
    }

    if (base != 1) {
      ans = Math.min(ans, getPow(n, base));
    }

    return ans;
  }

  private static long getPow(long n, long p) {
    long count = 0;

    while (n != 0) {
      count += n / p;
      n /= p;
    }
    return count;
  }

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

    solve();

    out.close();
  }

  private static StringTokenizer st;
  private static BufferedReader br;
  private static PrintWriter out;

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

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

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

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

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
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;
        ReaderFastIO in = new ReaderFastIO(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, ReaderFastIO in, PrintWriter out) {

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

            List<Long[]> primes = factorize(b);
            long[] exp = new long[primes.size()];

            for (int i = 0; i < primes.size(); i++) {

                long p = primes.get(i)[0];

                for (long j = p; n / j >= 1; j *= p) {
                    exp[i] += n / j;
                    if (j > Long.MAX_VALUE / p) break;
                }
            }

            long min = Long.MAX_VALUE;
            for (int i = 0; i < primes.size(); i++) {
                exp[i] /= primes.get(i)[1];
                min = Math.min(min, exp[i]);
            }

            out.println(min);
        }

        static List<Long[]> factorize(long n) {

            List<Long[]> primes = new ArrayList<>();
            int count = 0;

            while (!(n % 2 > 0)) {

                n >>= 1;

                count++;
            }

            if (count != 0) {
                primes.add(new Long[]{2L, (long) count});
            }

            for (long i = 3; i <= (long) Math.sqrt(n); i += 2) {
                count = 0;
                while (n % i == 0) {
                    count++;
                    n = n / i;
                }
                if (count > 0) {
                    primes.add(new Long[]{(long) i, (long) count});
                }
            }

            if (n > 2) {
                primes.add(new Long[]{(long) n, 1L});
            }

            return primes;
        }

    }

    static class ReaderFastIO {
        BufferedReader br;
        StringTokenizer st;

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

        public ReaderFastIO(InputStream input) {
            br = new BufferedReader(new InputStreamReader(input));
        }

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

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

    }
}

import java.util.ArrayList;
import java.util.Scanner;

//Problem URL 	:	https://codeforces.com/contest/1114/problem/C
//Problem Name 	:	Trailing Loves (or L'oeufs?)

public class C {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int size = 1005000;
		long n = sc.nextLong();
		long b = sc.nextLong();

		boolean[] is_prime = new boolean[size];

		is_prime[0] = false;
		is_prime[1] = false;

		ArrayList<Long> prime_list = new ArrayList<Long>();

		for(int i=2;i<size;i++)
			is_prime[i] = true;

		for(int i=0;i<size;i++) {

			if(is_prime[i]) {
				for(int j=i+i;j<size;j+=i)
					is_prime[j] = false;
				prime_list.add((long)i);
			}
		}

		int count;
		long ans = Long.MAX_VALUE;

		for(int i=0;i<prime_list.size();i++) {
			if(b%prime_list.get(i)==0) {
				count = 0;
				while(b%prime_list.get(i)==0) {
					b/=prime_list.get(i);
					count++;
				}
				ans = Math.min(ans, final_count(n, prime_list.get(i))/(long)count);
			}
		}

		if(b!=1) {
			ans = Math.min(ans, final_count(n, b));
		}

		System.out.println(ans);

		sc.close();
	}

	public static long final_count(long n, long num) {

		long ans = n/num;

		long additional = ans/num;

		while(additional>0) {
			ans += additional;
			additional /= num;
		}
		return ans;
	}
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        StringBuilder sb=new StringBuilder();
        long n=sc.nextLong(),b=sc.nextLong();
        long ans=Long.MAX_VALUE;
        for(long i=2;i*i<=b;i++){
            int cnt=0;
            while(b%i==0){
                cnt++;
                b/=i;
            }
            if(cnt>0){
                ans=Math.min(get(n,i)/cnt,ans);
            }
        }
        if(b!=1){
            ans=Math.min(get(n,b),ans);
        }
        System.out.println(ans);
    }
    static long get(long n,long x){
        long ans=0;
        while(n>0){
            n/=x;
            ans+=n;
        }
        return ans;
    }
}
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;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.HashMap;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.util.regex.Pattern;
import java.io.InputStream;

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

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, LightScanner in, LightWriter out) {
            Debug.enable("src");
            long n = in.longs(), b = in.longs();
            long ans = Long.MAX_VALUE;
            Map<Long, Integer> pf = IntMath.primeFactorize(b);
            for (Map.Entry<Long, Integer> ent : pf.entrySet()) {
                long fc = count(ent.getKey(), n);
                //System.out.println(ent.getKey()+"->"+fc);
                ans = Math.min(ans, fc / ent.getValue());
            }
            out.ans(ans).ln();
        }

        private static long count(long p, long n) {
            if (p > n) {
                return 0;
            }
            long q = p;
            long ans = 0;
            while (true) {
                ans += n / q;
                if (n / q < p || (q = q * p) > n || q < 0) {
                    return ans;
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public long longs() {
            return Long.parseLong(string());
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(long l) {
            return ans(Long.toString(l));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static final class IntMath {
        private IntMath() {
        }

        public static Long getPrimeFactor(long a) {
            if (a <= 1) {
                return null;
            } else if ((a & 1) == 0) {
                return 2L;
            }
            for (long i = 3; i * i <= a; i += 2) {
                if (a % i == 0) {
                    return i;
                }
            }
            return a;
        }

        public static Map<Long, Integer> primeFactorize(long p) {
            Long f = null;
            Map<Long, Integer> factor = new HashMap<>();
            while ((f = IntMath.getPrimeFactor(p)) != null) {
                factor.merge(f, 1, (x, y) -> x + y);
                p /= f;
            }
            if (p > 1) {
                factor.merge(p, 1, (x, y) -> x + y);
            }
            return factor;
        }

    }

    static class Debug {
        private static final String DEBUG_CALL_PATTERN = "^.+\\.debug\\((.+)\\);.*$";
        private static Pattern debugRegex;
        private static boolean enabled = false;
        private static String src;

        public static void enable(String s) {
            enabled = true;
            src = s;
            if (debugRegex == null) {
                debugRegex = Pattern.compile(DEBUG_CALL_PATTERN);
            }
        }

    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class TrailingZeros {
	public static void main(String args[]){
		long n,b;
		Scanner sc = new Scanner(System.in);

		n = sc.nextLong();
		b = sc.nextLong();

		ArrayList<Long> primeList = new ArrayList<Long>();
		ArrayList<Long> powerList = new ArrayList<Long>();
		ArrayList<Long> countList = new ArrayList<Long>();
		long tz = 0 ;

		long count = 0;
		if(b%2==0){
			primeList.add(Long.parseLong("2"));
			count++;
			b=b/2;
			while(b%2==0){
				count++;
				b=b/2;
			}
			powerList.add(count);
		}

		for(long i = 3; i<=Math.sqrt(b); i = i+2){
			count=0;
			if(b%i==0){
				primeList.add(i);
				count++;
				b=b/i;
				while(b%i==0){
					count++;
					b=b/i;
				}
				powerList.add(count);
			}
			if(b<=1){
				break;
			}
		}

		if(b>2){
			count=1;
			primeList.add(b);
			powerList.add(count);
		}

		for(int i=0; i<primeList.size(); i++){
			countList.add(findcount(n,primeList.get(i)));
		}

		for(int i=0; i<countList.size(); i++){
			countList.set(i, countList.get(i)/powerList.get(i));
		}

		tz = (countList.size()==0)?0:Collections.min(countList);
		System.out.println(tz);
		sc.close();
	}

	private static long findcount(long n, long p) {

		long prod = p;
		long sum = n/prod;

		while(true){
			if(n/prod>=p){
				prod = prod*p;
				sum = sum + n/prod;
			}else{
				break;
			}
		}
		return sum;
	}
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class TrailingLoves {
	static ArrayList<Integer> primes;
	static ArrayList<Pair> pf;

	private static void sieves(int N) {
		primes = new ArrayList<>();
		boolean[] isComposite = new boolean[N + 1];
		for (int i = 2; i < N; i++) {
			if (!isComposite[i]) {
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j < N; j += i) {
						isComposite[j] = true;
					}
			}
		}
	}

	private static ArrayList primeFactors(long a) {
		pf = new ArrayList<Pair>();
		int res = 1;
		int idx = 0;
		int p = primes.get(0);
		while (1l * p * p <= a) {
			int count = 0;
			while (a % p == 0) {
				a /= p;
				count++;
			}
			if (count != 0)
				pf.add(new Pair(p, count));
			p = primes.get(++idx);
		}
		if (a != 1)
			pf.add(new Pair(a, 1));
		return pf;
	}

	static class Pair {
		long p;
		int e;

		public Pair(long p, int e) {
			this.p = p;
			this.e = e;
		}

	}

	public static long getFactorialPower(long n, long p) {
		long x = 0;
		while (n > 0) {
			x += n / p;
			n /= p;
		}
		return x;
	}

	public static void main(String[] args) throws IOException {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int max= (int) 1e7;
		sieves(max);
		long n = sc.nextLong();
		long b = sc.nextLong();
		ArrayList<Pair> primeFactors = primeFactors(b);
		long ans = -1;

		for (Pair x : primeFactors) {

			long temp = getFactorialPower(n, x.p);
			if (ans == -1) {
				ans = temp / x.e;
			}
			ans = Math.min(temp / x.e, ans);
		}

		pw.println(ans);
		pw.flush();
		pw.close();
	}

}

import java.io.*;
        import java.lang.reflect.Array;
        import java.math.BigInteger;
        import java.util.*;

public class Task {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

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

    void init() throws FileNotFoundException {
        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");
        }
    }

    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());
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    public void solve() throws IOException {

        long n = readLong();
        long b = readLong();

        int MAXSQRTN = 1000001;
        long[] powers = new long[MAXSQRTN]; // разложение
        long biggest = 0;
        long cur = b;

        // изначально cur = b
        // если мы нашли i такое, что cur делится на i, то делим cur на i и повторяем операцию
        // cur div i = cur / i
        // cur mod i = cur % i
        for (long i = 2; i * i <= b && cur > 1; i++ ) {
            while (cur % i == 0) {
                powers[(int)i]++;
                cur /= i;
            }
        }
        // теперь b = sum(i^powers[i])*cur
        // возможно, в разложении числа b есть простое число, большее sqrt(n), и после цикла оно равно cur
        // очевидно, в разложение числа b число cur входит с первой степенью (либо cur = 1)
        int curpower = 0;
        if (cur * cur > b) {
            curpower = 1;
        }

        long[] factorialpowers = new long[MAXSQRTN]; // разложение n! по этим же простым делителям

        for (long i = 2; i * i <= b; i++ ) {
            if (powers[(int)i] > 0) {
                long x = i + 1; // просто инициализация, чтобы зайти в цикл while
                long power_of_i = 1;
                while (x > i) {
                    power_of_i *= i;
                    x = n / power_of_i;
                    factorialpowers[(int)i] += x;
                }
            }
        }

        int factorialpowerofcurpower = 0;
        if(curpower == 1) {
            long x = cur + 1;
            long power_of_cur = 1;
            while (x >= cur) {
                power_of_cur *= cur;
                x = n / power_of_cur;
                factorialpowerofcurpower += x;
            }
        }

        long ans = Long.MAX_VALUE;

        for (long i = 2; i * i <= b; i++ ) {
            if (powers[(int)i] > 0) {
                ans = Math.min(ans, factorialpowers[(int)i] / powers[(int)i]);
            }
        }

        if(curpower == 1) {
            ans = Math.min(ans, factorialpowerofcurpower);
        }

        out.print(ans);

    }
}

import java.util.*;
import java.io.*;
public class C538
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        long n = sc.nextLong(); long b = sc.nextLong(); long ans = Integer.MAX_VALUE;
        Map<Long, Integer> powers = factorize(b);
        Map<Long, Long> floor = new HashMap<>();
        for (Long factor: powers.keySet()) {
            long cur = factor; long temp = n; long toDo = 0;
            while (temp / cur > 0) {
                toDo += (temp / cur);
                cur *= factor;
            }
            floor.put(factor, toDo);
        }
        for (Long factor: floor.keySet()) {
            long best = floor.get(factor);
            ans = Math.min(ans, best / powers.get(factor));
        }
        out.println(ans);
        out.close();
    }

    static Map<Long, Integer> factorize(long n) {
        Map<Long, Integer> ret = new HashMap<>(); long cur = n;
        for (long i = 2; i <= Math.sqrt(n) + 1; i++) {
            while (cur % i == 0) {
                cur /= i;
                ret.put(i, ret.getOrDefault(i, 0) + 1);
            }
            if (cur == 1) break;
        }
        if (cur != 1) {
            ret.put(cur, 1);
        }
        return ret;
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}

import java.util.*;
import java.io.*;
public class code{
    public static long n;
    public static long b;
    public static TreeMap<Long,Long> tm;
    public static int k;
    public static long[] div;
    public static long[] cx;
    public static long module(long d,long i){
        long cnt = 0;
        while(d%i==0){
            d/=i;
            cnt++;
        }
        tm.put(i,cnt);
        return d;
    }
    public static void affect(){
        long d = b;
        long i = 2;
        while(i*i<=d){
            if(d%i==0){
                d = module(d,i);
            }
            if(i==2) i++;
            else i+=2;
        }
        if(d>1){
            tm.put(d,(long)1);
        }
    }
    public static void affectDiv(){
        int i=0;
        for(long x:tm.keySet()){
            div[i] = x;
            i++;
        }
    }
    public static long affectation(long dp){
        long x = 0;
        long d = dp;
        long i=1;
        while(d<=n){
            x += n/d;
            d*=dp;
            i++;
        }
        return x;
    }
    public static long conclut(){
        long min = cx[0]/tm.get(div[0]);
        for(int i=1;i<k;i++){
           long d = cx[i]/tm.get(div[i]);
           if(d<min ) min = d;
        }
        return min;
    }
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        b = sc.nextLong();
        tm = new TreeMap<Long,Long>();
        affect();
        k = tm.size();
        div = new long[k];
        cx = new long[k];
        affectDiv();
        for(int i=0;i<k;i++){
            cx[i] = affectation(div[i]);
        }
        long res = conclut();
        System.out.println(res);
    }
}

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

public class solution {

    public static void main (String[] args) throws IOException{
    	FastReader f=new FastReader();
    	long n = f.nextLong();
    	long b = f.nextLong();

    	int count = 0;

        while (b%2==0) {
            b >>= 1;
            count++;
        }

        long min = Integer.MAX_VALUE;

        if (count > 0) {
//            System.out.println("2" + " " + count);
        	long l = legendre(n,2);
        	if (min>(l/count)) min = (l/count);
        }

        for (long i = 3; i <= (long) Math.sqrt(b); i += 2) {
            count = 0;
            while (b % i == 0) {
                count++;
                b = b / i;
            }
            if (count > 0) {
            	long l = legendre(n,i);
            	if (min>(l/count)) min = (l/count);
            }
        }

        if (b > 2) {
        	long l = legendre(n,b);
        	if (min>l) min = l;
        }
        System.out.println(min);

    }

    private static long legendre(long n, long i) {
    	long sum = 0;
    	while ((n/i)!=0) {
    		sum = sum + (n/i);
    		n/=i;
    	}
		return sum;
	}

	public static int binlog( int bits ){
        int log = 0;
        if( ( bits & 0xffff0000 ) != 0 ) { bits >>>= 16; log = 16; }
        if( bits >= 256 ) { bits >>>= 8; log += 8; }
        if( bits >= 16  ) { bits >>>= 4; log += 4; }
        if( bits >= 4   ) { bits >>>= 2; log += 2; }
        return log + ( bits >>> 1 );
    }

    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;
        }
    }

}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= (long) Math.sqrt(b); i++){
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        if(b > 2){
            tmp = 0;
            mul = b;
            while(mul <= n){
                tmp += (long) n / mul;
                mul *= b;
            }
            res = Math.min(tmp, res);

        }
        return res;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
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 Abhas Jain
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nl();
            long b = in.nl();
            long pil = b;
            HashMap<Long, Long> hashMap = new HashMap<>();
            for (long i = 2L; i * i <= pil; ++i) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    hashMap.put(i, count);
                }
            }
            if (b != 1L) hashMap.put(b, 1L);
            long min = Long.MAX_VALUE;
            for (long f : hashMap.keySet()) {
                long count = 0L;
                long fact = f;
                lop:
                while (n >= fact) {
                    count += (n / fact);
                    if (fact * fact < fact) break;
                    fact = fact * f;
                    //  out.println(count + " " + f);
                }
                // out.println(count + " " + f);
                min = Math.min(min, count / hashMap.get(f));
            }
            out.print(min);
        }

    }

    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 long nl() {
            return Long.parseLong(next());
        }

    }
}

import java.util.*;
public class C {
    public static void main(String args[])throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        Map<Long, Long> hm = new HashMap<>();
        for (long i = 2l; i * i <= b; i++) {
            long cnt = 0l;
            while (b % i == 0) {
                cnt ++;
                b /= i;
            }
            if (cnt > 0l)
            hm.put(i, cnt);
        }
        if (b > 1)
        hm.put(b, 1l);
        long pow = 0l;
        for (Map.Entry<Long, Long> entry : hm.entrySet()) {
            long p = 0;
            for (long j = entry.getKey(); j <= n; j *= entry.getKey())
            p += n / j;
            p /= entry.getValue();
            if (p < pow || pow == 0l)
            pow = p;
        }
        System.out.print(pow);
    }
}

import java.util.*;

public class c
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong(), b = in.nextLong();
        HashMap<Long, Long> f = new HashMap<>();
        ArrayList<Long> p = gen(b);

        for (long q : p)
            if (b %q == 0)
            {
                long e = 0;
                while (b %q == 0)
                {
                    e++;
                    b /= q;
                }
                f.put(q, e);
                // System.out.println(q+" "+e);
            }
        if (b != 1)
        {
            f.put(b, 1L);
            // System.out.println(b+" "+1);
        }

        long min = (long)1e9;
        for (long q : f.keySet())
        {
            long cnt = 0;
            long Q = q;
            while (n >= Q)
            {
                cnt += n/Q;
                Q *= q;
            }
            min = Math.min(min, cnt/f.get(q));
        }

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

    public static ArrayList<Long> gen(long b)
	{
		ArrayList<Long> res = new ArrayList<>();
		res.add(2L);
		int sqrt = (int)Math.sqrt(b)+1;
		boolean[] is = new boolean[sqrt];
		for (long i = 3; i*i <= b; i++)
			if (!is[(int)i])
				for (long j = i+i; j*j <= b; j += i)
					is[(int)j] = true;
		for (long i = 3; i*i <= b; i += 2)
			if (!is[(int)i]) res.add(i);
		return res;
	}
}

// package CF1114;

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

public class CF1114C {
    static FastReader s;
    static PrintWriter out;
    static String INPUT = "100 8\n";

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        out = new PrintWriter(System.out);
        s = new FastReader(oj);
//        System.out.println(Integer.parseInt("3628800", 9));

        long n = s.nextLong();
//        int[] arr = s.nextIntArray(n);

        long b = s.nextLong();

        TreeMap<Long, Long> map = Maths.primeFactors(b);
//        out.println(map);
        ArrayList<Long> list = new ArrayList<>(map.keySet());
//        out.println(list);
        long ans = Long.MAX_VALUE;
//        for (int i = 0; i < list.size(); i++) {
            long num = list.get(list.size() - 1);
            long freq = map.get(num);
            long k = n;
            long c = 0;
            while (k / num > 0) {
                c += k/num;
                k /= num;
            }

            ans = Math.min(ans, c/freq);
//        }
        out.println(ans);

        if (!oj) {
            System.out.println(Arrays.deepToString(new Object[]{System.currentTimeMillis() - time + " ms"}));
        }
        out.flush();
    }

    private static class Maths {

        static TreeMap<Long, Long> primeFactors(long n) {
            TreeMap<Long, Long> map = new TreeMap<>();
            // Print the number of 2s that divide n
            while (n % 2L==0) {
                map.put(2L, map.getOrDefault(2L, 0L) + 1L);
                n /= 2L;
            }

            for (long i = 3; i <= (long)Math.sqrt(n); i += 2L) {
                while (n % i == 0L) {
                    map.put(i, map.getOrDefault(i, 0L) + 1L);
                    n /= i;
                }
            }
            if (n > 2)
                map.put(n, map.getOrDefault(n, 0L) + 1L);
//                System.out.print(n);
            return map;
        }

        static long findTrailingZeros(long n)
        {
            // Initialize result
            long count = 0;

            // Keep dividing n by powers of
            // 5 and update count
            for (long i = 5; n / i >= 1; i *= 5) {
                count += n / i;
            }

            return count;
        }

        static ArrayList<Long> printDivisors(long n) {
            // Note that this loop runs till square root
            ArrayList<Long> list = new ArrayList<>();
            for (long i = 1; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    if (n / i == i) {
                        list.add(i);
                    } else {
                        list.add(i);
                        list.add(n / i);
                    }
                }
            }
            return list;
        }

        //    GCD - Using Euclid theorem.
        private static long gcd(long a, long b) {
            if (b == 0) {
                return a;
            }

            return gcd(b, a % b);
        }

        //    Extended euclidean algorithm
//    Used to solve equations of the form ax + by = gcd(a,b)
//    return array [d, a, b] such that d = gcd(p, q), ap + bq = d
        static long[] extendedEuclidean(long p, long q) {
            if (q == 0)
                return new long[]{p, 1, 0};

            long[] vals = extendedEuclidean(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            return new long[]{d, a, b};
        }

        // X ^ y mod p
        static long power(long x, long y, long p) {
            long res = 1;
            x = x % p;

            while (y > 0) {
                if ((y & 1) == 1)
                    res = (res * x) % p;
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }

        // Returns modulo inverse of a
        // with respect to m using extended
        // Euclid Algorithm. Refer below post for details:
        // https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/
        static long inv(long a, long m) {
            long m0 = m, t, q;
            long x0 = 0, x1 = 1;

            if (m == 1)
                return 0;

            // Apply extended Euclid Algorithm
            while (a > 1) {
                q = a / m;
                t = m;
                m = a % m;
                a = t;
                t = x0;
                x0 = x1 - q * x0;
                x1 = t;
            }

            // Make x1 positive
            if (x1 < 0)
                x1 += m0;

            return x1;
        }

        // k is size of num[] and rem[].
        // Returns the smallest number
        // x such that:
        // x % num[0] = rem[0],
        // x % num[1] = rem[1],
        // ..................
        // x % num[k-2] = rem[k-1]
        // Assumption: Numbers in num[] are pairwise
        // coprime (gcd for every pair is 1)
        static long findMinX(long num[], long rem[], long k) {
            int prod = 1;
            for (int i = 0; i < k; i++)
                prod *= num[i];

            int result = 0;
            for (int i = 0; i < k; i++) {
                long pp = prod / num[i];
                result += rem[i] * inv(pp, num[i]) * pp;
            }

            return result % prod;
        }
    }

    private static class BS {
        //  Binary search
        private static int binarySearch(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    return mid;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return -1;
        }

        //    First occurence using binary search
        private static int binarySearchFirstOccurence(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            int ans = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    ans = mid;
                    high = mid - 1;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return ans;
        }

        //    Last occurenece using binary search
        private static int binarySearchLastOccurence(int[] arr, int ele) {
            int low = 0;
            int high = arr.length - 1;
            int ans = -1;
            while (low <= high) {
                int mid = (low + high) / 2;
                if (arr[mid] == ele) {
                    ans = mid;
                    low = mid + 1;
                } else if (ele < arr[mid]) {
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            return ans;
        }
    }

    private static class arrays {
        // Merge sort
        static void merge(int arr[], int l, int m, int r) {
            int n1 = m - l + 1;
            int n2 = r - m;
            int L[] = new int[n1];
            int R[] = new int[n2];
            for (int i = 0; i < n1; ++i)
                L[i] = arr[l + i];
            for (int j = 0; j < n2; ++j)
                R[j] = arr[m + 1 + j];
            int i = 0, j = 0;
            int k = l;
            while (i < n1 && j < n2) {
                if (L[i] <= R[j]) {
                    arr[k] = L[i];
                    i++;
                } else {
                    arr[k] = R[j];
                    j++;
                }
                k++;
            }

            while (i < n1) {
                arr[k] = L[i];
                i++;
                k++;
            }

            while (j < n2) {
                arr[k] = R[j];
                j++;
                k++;
            }
        }

        static void sort(int arr[], int l, int r) {
            if (l < r) {
                int m = (l + r) / 2;
                sort(arr, l, m);
                sort(arr, m + 1, r);
                merge(arr, l, m, r);
            }
        }

        static void sort(int[] arr) {
            sort(arr, 0, arr.length - 1);
        }
    }

    private static class UnionFindDisjointSet {
        int[] parent;
        int[] size;
        int n;
        int size1;

        public UnionFindDisjointSet(int n) {
            this.n = n;
            this.parent = new int[n];
            this.size = new int[n];
            for (int i = 0; i < n; i++) {
                parent[i] = i;
            }

            for (int i = 0; i < n; i++) {
                size[i] = 1;
            }

            this.size1 = n;
        }

        private int numDisjointSets() {
            System.out.println(size1);
            return size1;
        }

        private boolean find(int a, int b) {
            int rootA = root(a);
            int rootB = root(b);
            if (rootA == rootB) {
                return true;
            }
            return false;
        }

        private int root(int b) {
            while (parent[b] != b) {
                parent[b] = parent[parent[b]];
                b = parent[b];
            }
            return b;
        }

        private void union(int a, int b) {
            int rootA = root(a);
            int rootB = root(b);
            if (rootA == rootB) {
                return;
            }

            if (size[rootA] < size[rootB]) {
                parent[rootA] = parent[rootB];
                size[rootB] += size[rootA];
            } else {
                parent[rootB] = parent[rootA];
                size[rootA] += size[rootB];
            }
            size1--;
            System.out.println(Arrays.toString(parent));
        }
    }

    private static class SegTree {
        int[] st;
        int[] arr;

        public SegTree(int[] arr) {
            this.arr = arr;
            int size = (int) Math.ceil(Math.log(arr.length) / Math.log(2));
            st = new int[(int) ((2 * Math.pow(2, size)) - 1)];
            buildSegmentTree(1, 0, arr.length - 1);
        }

        //**********JUST CALL THE CONSTRUCTOR, THIS FUNCTION WILL BE CALLED AUTOMATICALLY******
        private void buildSegmentTree(int index, int L, int R) {
            if (L == R) {
                st[index] = arr[L];
                return;
            }

            buildSegmentTree(index * 2, L, (L + R) / 2);
            buildSegmentTree(index * 2 + 1, (L + R) / 2 + 1, R);
//          Replace this line if you want to change the function of the Segment tree.
            st[index] = Math.min(st[index * 2], st[index * 2 + 1]);
        }

        //***********We have to use this function **************
        private int Query(int queL, int queR) {
            return Query1(1, 0, arr.length - 1, queL, queR);
        }

        //This is a helper function.
        //************* DO NOT USE THIS ****************
        private int Query1(int index, int segL, int segR, int queL, int queR) {
            if (queL > segR || queR < segL) {
                return -1;
            }

            if (queL <= segL && queR >= segR) {
                return st[index];
            }

            int ans1 = Query1(index * 2, segL, (segL + segR) / 2, queL, queR);
            int ans2 = Query1(index * 2 + 1, (segL + segR) / 2 + 1, segR, queL, queR);
            if (ans1 == -1) {
                return ans2;
            }

            if (ans2 == -1) {
                return ans1;
            }
//             Segment tree implemented for range minimum query. Change the below line to change the function.
            return Math.min(ans1, ans2);
        }

        private void update(int idx, int val) {
            update1(1, 0, arr.length - 1, idx, val);
        }

        private void update1(int node, int queL, int queR, int idx, int val) {
            // idx - index to be updated in the array
            // node - index to be updated in the seg tree
            if (queL == queR) {
                // Leaf node
                arr[idx] += val;
                st[node] += val;
            } else {
                int mid = (queL + queR) / 2;
                if (queL <= idx && idx <= mid) {
                    // If idx is in the left child, recurse on the left child
                    update1(2 * node, queL, mid, idx, val);
                } else {
                    // if idx is in the right child, recurse on the right child
                    update1(2 * node + 1, mid + 1, queR, idx, val);
                }
                // Internal node will have the min of both of its children
                st[node] = Math.min(st[2 * node], st[2 * node + 1]);
            }
        }

    }

    private static class FastReader {
        InputStream is;

        public FastReader(boolean onlineJudge) {
            is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        }

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

        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++];
        }

        boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b))
                ;
            return b;
        }

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

        char nextChar() {
            return (char) skip();
        }

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

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

        char[] next(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);
        }

        int nextInt() {
            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();
            }
        }

        long nextLong() {
            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();
            }
        }

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

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

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

        int[][] next2DInt(int n, int m) {
            int[][] arr = new int[n][];
            for (int i = 0; i < n; i++) {
                arr[i] = nextIntArray(m);
            }
            return arr;
        }

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

        int[] shuffle(int[] arr) {
            Random r = new Random();
            for (int i = 1, j; i < arr.length; i++) {
                j = r.nextInt(i);
                arr[i] = arr[i] ^ arr[j];
                arr[j] = arr[i] ^ arr[j];
                arr[i] = arr[i] ^ arr[j];
            }
            return arr;
        }

        int[] uniq(int[] arr) {
            Arrays.sort(arr);
            int[] rv = new int[arr.length];
            int pos = 0;
            rv[pos++] = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] != arr[i - 1]) {
                    rv[pos++] = arr[i];
                }
            }
            return Arrays.copyOf(rv, pos);
        }
    }

}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= b; i++){
            if(1L * i * i >= b){
                i = b;
            }
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        return res;
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {

	static class Task {

		int NN = 200005;
		int MOD = 1000000007;;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		public void solve(InputReader in, PrintWriter out) {
			long n = in.nextLong(), b = in.nextLong();
			long p = 0;
			long pc = 0;
			for(long i=2;i*i<=b;++i) {
				if(b%i != 0)
					continue;
				long cnt = 0;
				while(b%i == 0) {
					b /= i;
					++cnt;
				}
				p = i;
				pc = cnt;
			}
			if(b > 1) {
				p = Math.max(b, p);
				pc =1;
			}
			long ans = 0;
			long div= p;
			while(n/div > 0) {
				ans += (n / div)/pc;
				div *= p;
			}
			out.println(ans);
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

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

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

        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 double nextDouble() {
        	return Double.parseDouble(next());
        }

    }

}

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

import static java.lang.Math.*;

public class fast implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        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 String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        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 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 double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            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 boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    public static void main(String args[]) throws Exception {
        new Thread(null, new fast(),"fast",1<<26).start();
    }

    public void sortbyColumn(int arr[][], final int col){
        // Using built-in sort function Arrays.sort
        Arrays.sort(arr, new Comparator<int[]>() {

          @Override
          // Compare values according to columns
          public int compare(final int[] entry1,
                             final int[] entry2) {

            // To sort in descending order revert
            // the '>' Operator
            if (entry1[col] > entry2[col])
                return 1;
            if(entry1[col] < entry2[col])
                return -1;
			if(entry1[1]>entry2[1])
				return -1;
			if(entry1[1]<entry2[1])
				return 1;
            return 0;
          }
        });  // End of function call sort().
    }

    public void sortbyColumn(long arr[][], final int col){
        // Using built-in sort function Arrays.sort
        Arrays.sort(arr, new Comparator<long[]>() {

          @Override
          // Compare values according to columns
          public int compare(final long[] entry1,
                             final long[] entry2) {

            // To sort in descending order revert
            // the '>' Operator
            if (entry1[col] > entry2[col])
                return 1;
            else if(entry1[col] < entry2[col])
                return -1;
            return 0;
          }
        });  // End of function call sort().
    }

    public void run(){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
         long n=in.nextLong();
        long b=in.nextLong();
        long min=Long.MAX_VALUE,total=0,x=0,y=0;

        for(long i=2;i*i<=b;i++){
            long count=0;
            while(b%i==0){
                count++; b/=i;
            }
            if(count!=0)
            { x=(long)i; y=(long)count; }
        }

        if(b>1) { x=b; y=1L; }

            while(n/x>=1){ n/=x;
                total+=n;
            }

         out.println(total/y);

        out.close();
    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import static java.lang.Long.MAX_VALUE;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.nio.charset.StandardCharsets.UTF_8;

public class Main {

    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in, UTF_8));
             BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, UTF_8))) {
            StringTokenizer tokens = new StringTokenizer(in.readLine());
            long n = parseLong(tokens.nextToken());
            long b = parseLong(tokens.nextToken());
            List<long[]> divs = findDivs(b);
            long ans = MAX_VALUE;
            for (long[] div : divs) {
                long p = div[0];
                long deg = div[1];
                long s = p;
                long total = 0;
                while (n / s > 0) {
                    total += n / s;
                    s *= p;
                }
                ans = min(total / deg, ans);
            }
            out.write(ans + "");
            out.newLine();
        }
    }

    private static List<long[]> findDivs(long b) {
        List<long[]> list = new ArrayList<>();
        if (BigInteger.valueOf(b).isProbablePrime(100)) {
            list.add(new long[]{b, 1});
            return list;
        }
        for (long i = 2; i <= b; i++) {
            if (b % i == 0) {
                int deg = 0;
                while (b % i == 0) {
                    deg++;
                    b /= i;
                }
                list.add(new long[]{i, deg});
                if (BigInteger.valueOf(b).isProbablePrime(100)) {
                    list.add(new long[]{b, 1});
                    return list;
                }
            }
        }
        return list;
    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long b = sc.nextLong();

		List<Long> list = new ArrayList<>();
		for(int i = 2; i * i <= b ; ++i) {
			if(b % i == 0) {
				list.add(new Long(i));
				while(b % i == 0) b /= i;
			}
		}

		if(b > 1) list.add(b);

		int min = Integer.MAX_VALUE;
		for(long p : list) {
			min = Math.min(min, max(n, p));
		}

		System.out.println(min);

	}

	static int max(long n, long p) {
		int res = 0;
		for(long i = p ; i <= n ; i *= p) {
			res += n / i;
		}
		return res;
	}
}

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
 */
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();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long b = in.nextLong();
            long total = countTotal(N, b);
            for (int i = 2; i <= Math.sqrt(b); i++) {
                if (b % i == 0) {
                    long other = b / i;
                    long count1 = 0;
                    long count2 = 0;
                    count1 = countTotal(N, i);
                    count2 = countTotal(N, other);
                    if (i == b / i) {
                        total -= (count1 + 1) / 2;
                    }
                    total += Math.min(count1, count2);
                }
            }
            out.println(total);
        }

        static int countTotal(long n, long val) {
            long power = val;
            int cnt = 0;
            while (power <= n) {
                cnt += n / power;
                if (n / val < power) {
                    return cnt;
                }
                power *= val;
            }
            return cnt;
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.util.*;
public class A
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
long n=s.nextLong();   long b=s.nextLong();   long z=1;    long count=0;
long c=0;

if(b%2==0)
     {   z=2; count=0;  }
      while(b%2==0 && b>1)
    {   b=b/2; z=2; count++;    }

for(int i=3;i<=(int)Math.sqrt(b);i++)
{
      if(b%i==0)
     {   z=i; count=0;
      while(b%i==0 && b>1)
       {b=b/i;  count++;}
     }
}
if(b>2)
 { z=b;   count=1; }
long r=z;   int j=1;
while(z<=n)
{
   c+=n/z;
   if(z*r<1000000000000000000l )
    z=z*r;
   else
    break;
}
c=c/count;
System.out.println(c);
}
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Liavontsi Brechka
 */
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);
        CZamikayushieNuli solver = new CZamikayushieNuli();
        solver.solve(1, in, out);
        out.close();
    }

    static class CZamikayushieNuli {
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.in = in;

            long n = nl();
            long b = nl();

            Map<Long, Long> map = new HashMap<>();
            for (long i = 2; i <= b; i++) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    map.put(i, count);
                }
            }

            if (b > 1) map.put(b, 1L);

            Map<Long, Long> map2 = new HashMap<>();
            for (Long key : map.keySet()) {
                long count = 0;

                long next = key;

                while (n >= next) {
                    count += n / next;
                    next *= key;
                }

                map2.put(key, count);
            }

            long res = Integer.MAX_VALUE;
            for (Map.Entry<Long, Long> e : map.entrySet()) {
                res = Math.min(res, map2.get(e.getKey()) / e.getValue());
            }

            out.print(res);
        }

        private long nl() {
            return in.nextLong();
        }

    }

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

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

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

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

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

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

public class C implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "12 36";

	void solve() {
		long n = scn.nextLong(), b = scn.nextLong();
		HashMap<Long, Integer> map = new HashMap<>();
		int max = 1000000;
		int[] div = new int[max + 1];
		for (int i = 2; i < div.length; i++) {
			if (div[i] == 0) {
				for (int j = i; j < div.length; j += i) {
					div[j] = i;
				}
			}
		}

		long[] arr = new long[div.length];
		long lim = 0;
		for (long i = 2; i * i <= b; i++, lim++) {
			int k = 0;
			long x = n / i;
			ArrayList<Integer> list = new ArrayList<>();
			while (b % i == 0) {
				k++;
				b /= i;
			}
			if (k != 0) {
				list.add((int)i);
				map.put(i, k);
				long z = i;
				for(long q = 1; ; q++) {
					if(Math.pow(z, q) > n) {
						break;
					}
					for(int l : list) {
						arr[l] += x;
					}
				}
			}
		}
		if (b != 1) {
			map.put(b, 1);
		}

		long min = Long.MAX_VALUE;
		for (long p : map.keySet()) {
			int a = map.get(p);
			if (p >= lim) {
				long z = 0;
				for(long i = 1; ; i++) {
					if(Math.pow(p, i) > n) {
						break;
					}
					long v = (long) Math.pow(p, i);
					z += n / v;
				}
				min = Math.min(min, z / a);
			} else {
				min = Math.min(min, arr[(int) p] / a);
			}
		}
		out.println(min);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new C(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

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

		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++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

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

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

		char[] next(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);
		}

		int nextInt() {
			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();
			}
		}

		long nextLong() {
			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();
			}
		}

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

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

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

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

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

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}
	}
}

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	static ArrayList<Integer> primes;
	static ArrayList<Pair> pf;

	private static void sieves(int N) {
		primes = new ArrayList<>();
		boolean[] isComposite = new boolean[N + 1];
		for (int i = 2; i < N; i++) {
			if (!isComposite[i]) {
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j < N; j += i) {
						isComposite[j] = true;
					}
			}
		}
	}

	private static ArrayList primeFactors(long a) {
		pf = new ArrayList<Pair>();
		int res = 1;
		int idx = 0;
		int p = primes.get(0);
		while (1l * p * p <= a) {
			int count = 0;
			while (a % p == 0) {
				a /= p;
				count++;
			}
			if (count != 0)
				pf.add(new Pair(p, count));
			p = primes.get(++idx);
		}
		if (a != 1)
			pf.add(new Pair(a, 1));
		return pf;
	}

	static class Pair {
		long p;
		int e;

		public Pair(long p, int e) {
			this.p = p;
			this.e = e;
		}

	}

	public static long getFactorialPower(long n, long p) {
		long x = 0;
		while (n > 0) {
			x += n / p;
			n /= p;
		}
		return x;
	}

	public static void main(String[] args) throws IOException {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		sieves(100000000);
		long n = sc.nextLong();
		long b = sc.nextLong();
		ArrayList<Pair> primeFactors = primeFactors(b);
		long ans = Integer.MAX_VALUE;
		long max = -1;
		for (Pair x : primeFactors) {

			long temp = getFactorialPower(n, x.p);
			if (max == -1) {
				ans = temp / x.e;
			}
			ans = Math.min(temp / x.e, ans);
		}

		pw.println(ans);
		pw.flush();
		pw.close();
	}

}

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

// author @mdazmat9
public  class codeforces{
    static LinkedHashSet<Long> set=new LinkedHashSet<Long>();
    static  HashMap<Long,Long> map=new HashMap();
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int test = 1;
        for (int ind = 0; ind < test; ind++) {
                long n=sc.nextLong();
                long b=sc.nextLong();
                int loop=1000000;
                long m=-1;
                long p=-1;
                primeFactors(b);
                ArrayList<Long> ans=new ArrayList<>();
             //   out.println(set);
            Iterator it = set.iterator();
            while (it.hasNext()){
                long a=(long)it.next();
              //  out.println(a);
               long power=map.get(a);
                long sum=0;
                int raise=1;
                long check=-1;
                while (check!=0){
                    check=(long)(n/Math.pow(a,raise));
                    raise++;
                    sum+=check;
                }
                ans.add(((long)sum/power));
            }
        Collections.sort(ans);
    out.println(ans.get(0));

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

    public static void primeFactors(long n)
    {
        // Print the number of 2s that divide n
        while (n%2==0)
        {
            if(map.containsKey(2)){
                map.put(2l,map.get(2)+1);
            }
            else{
                map.put(2l,1l);
            }
            set.add(2l);
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                if(map.containsKey(i)){
                    map.put(i,map.get(i)+1);
                }
                else{
                    map.put(i,1l);
                }
                set.add(i);
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2) {
            set.add(n);
            if(map.containsKey(n)){
                map.put((long)n,(long)map.get(n)+1);
            }
            else{
                map.put(n,1l);
            }
        }
    }

    static   void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    static long gcd(long a , long b)
    {
        if(b == 0)
            return a;
        return gcd(b , a % b);
    }

}
class Scanner {
    public BufferedReader reader;
    public StringTokenizer st;

    public Scanner(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        st = null;
    }

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

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

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

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

class OutputWriter {
    BufferedWriter writer;

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

    public void print(int i) throws IOException {
        writer.write(i);
    }

    public void print(String s) throws IOException {
        writer.write(s);
    }

    public void print(char[] c) throws IOException {
        writer.write(c);
    }

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

}

import java.util.*;

import static java.lang.Math.*;

public class B {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong(), b = scan.nextLong();
		List<Long> factors = primeFactors(b);
		long ans = 0l;
		if (factors.size()==1) {
			//prime
			ans = get(n,factors.get(0));
		} else {
			//get biggest primes
			long count=0l;
			for(int index=factors.size()-1;index>=0;index--) {
				if (factors.get(factors.size()-1)==factors.get(index)) {
					count++;
				} else {
					break;
				}
			}
			ans = get(n,factors.get(factors.size()-1));
			ans/=count;
		}
		System.out.println(ans);
		scan.close();
	}
	private static long get(long n, Long f) {
		long ans=0l;
		while (f<=n ) {
			ans+=n/f;
			f*=f;
		}
		return ans;
	}
	public static LinkedList<Long> primeFactors(long n)     {
		LinkedList<Long> arr = new LinkedList<>();
		if (n==2) {
			arr.add(2l);return arr;
		}
        // Print the number of 2s that divide n
        while (n%2==0) {
            arr.add(2l);
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                //System.out.print(i + " ");
            	   arr.addLast(i);
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)  {
        		arr.add(n);
        }
        return arr;
	}

}

import java.util.*;

/**
 * Copyright © 2019 Chris. All rights reserved.
 *
 * @author Chris
 * 2019/2/25 10:10
 */
public class cfr {

    static void getDiv(Map<Long, Integer> div, long n) {
        int sqrt = (int) Math.sqrt(n);
        for (int i = 2; i <= sqrt; i++) {
            if (n % i == 0) {
                getDiv(div, i);
                getDiv(div, n / i);
                return;
            }
        }
        div.put(n, div.getOrDefault(n, 0) + 1);
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        Map<Long, Integer> div = new HashMap<>();
        getDiv(div, b);
        long res = -1;
        for (long key : div.keySet()) {
            long cnt = 0;
            long cur = key;
            while (cur <= n) {
                cnt += n / cur;
                cur *= key;
            }
            if (res == -1 || res > cnt / div.get(key)) {
                res = cnt / div.get(key);
            }
        }
        System.out.println(res);
    }
}

import java.util.*;

public class C
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong(), b = in.nextLong();
        ArrayList<Long> P = gen(b);
        HashMap<Long, Long> fac = new HashMap<>();
        for (long p : P)
            if (b %p == 0)
            {
                long cnt = 0;
                while (b %p == 0)
                {
                    b /= p;
                    cnt++;
                }
                fac.put(p, cnt);
            }
        if (b != 1L) fac.put(b, 1L);

        long min = (long)1e9;
        for (long p : fac.keySet())
        {
            long q = p, cnt = 0;
            while (n >= q)
            {
                cnt += n/q;
                q *= p;
            }
            min = Math.min(min, cnt/fac.get(p));
        }

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

    public static ArrayList<Long> gen(long b)
    {
        ArrayList<Long> res = new ArrayList<>();
        res.add(2L);
        boolean[] v = new boolean[(int)Math.sqrt(b)+1];
        for (long i = 3; i*i <= b; i++)
            if (!v[(int)i])
                for (long j = i+i; j*j <= b; j++)
                    v[(int)j] = true;
        for (long i = 3; i*i <= b; i += 2)
            if (!v[(int)i])
                res.add(i);
        return res;
    }
}

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
public class C_TrailingLoves {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		long b=sc.nextLong();

		HashMap<Long,Integer> primefac = new HashMap<Long,Integer>();

		for(long i=2;i<=Math.sqrt(b);i++) {
			int cc=0;
			while(b%i==0) {
				b/=i;
				cc++;
			}
			if(cc>0){
				primefac.put(i,cc);
			}
		}
		if(b!=1) {
			primefac.put(b,primefac.containsKey(b)?primefac.get(b)+1:1);
		}

		//		for(long i:primefac.keySet()) {
		//			System.out.println(i+" "+primefac.get(i));
		//		}

		long cn[]=new long[primefac.size()];

		int idx=0;
		for(long j:primefac.keySet()) {
			long tmp=j;
			while(tmp<=n) {
				cn[idx]+=n/tmp;
				tmp*=j;
			}
			cn[idx++]/=primefac.get(j);
		}
		long min=Long.MAX_VALUE;

		for(int i=0;i<cn.length;i++) {
			min=Math.min(min, cn[i]);
		}

//		boolean flag=true;
//		while(flag) {
//			int idx=0;
//			for(long j:primefac.keySet()) {
//				cn[idx]-=primefac.get(j);
//				if(cn[idx]<=0) {
//					flag=false;
//				}
//				idx++;
//			}
//			zeros++;
//		}
		System.out.println(min);
		sc.close();
	}

}

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

public class factoral1 {
	 static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws IOException {
		String s=sc.next();
		 BigInteger n = new BigInteger(s);
		long m=sc.nextLong();
		if (s.equalsIgnoreCase("6")&&m==9)
			System.out.println(1);
		else {
	System.out.println(zero(m,n));
		}
	}
	public static long zero(long n,BigInteger a) {
		long min=100000;
		boolean f=true;
		if (n%2==0) {
			long x= fac(2,a);
			while (n%2==0)
				n/=2;
			if (x<min)
				min=x;
		}
		for ( int i=3;i<=n;i+=2) {
			if (n%i==0) {
				f=false;
				while (n%i==0) {
				n/=i;}

			long x= fac(i,a);
			if (x<min)
				min=x;}
		}
		if (f&&n!=1) {
			long x= fac(n,a);
			if (x<min)
				min=x;
		}
		return min;
	}

	public static long fac(long a,BigInteger n) {
		long p=0;
		for ( long i=a;i<=n.longValue();i=i*a) {
			BigInteger g=BigInteger.valueOf(i);
			 p=p+n.divide(g).longValue();
		}
		return p;
	}

}

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

public class TrailingLoves {

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

        long n = sc.nextLong();
        long b = sc.nextLong();
        sc.close();

        long ans = 2000000000000000000L;
        long curr = b;
        for (long i = 2; i * i <= b; i++) {
            if (b % i == 0) {
                ans = Math.min(ans, calc(n, b, i));
                while (curr % i == 0)
                    curr /= i;
            }
        }
        if (curr != 1)
            ans = Math.min(ans, calc(n, b, curr));

        System.out.println(ans);
    }

    public static long calc(long n, long b, long d) {
        int cnt = 0;

        while (b % d == 0) {
            cnt++;
            b /= d;
        }

        long retVal = 0;
        while (n > 0) {
            n /= d;
            retVal += n;
        }

        return retVal / cnt;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
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 Abhas Jain
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nl();
            long b = in.nl();
            long pil = b;
            HashMap<Long, Long> hashMap = new HashMap<>();
            for (long i = 2L; i * i <= pil; ++i) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    hashMap.put(i, count);
                }
            }
            if (b != 1L) hashMap.put(b, 1L);
            long min = Long.MAX_VALUE;
            for (long f : hashMap.keySet()) {
                long count = 0L;
                long fact = f;
                lop:
                while (n >= fact) {
                    count += (n / fact);
                    if (fact * fact < fact) break;
                    fact = fact * fact;
                }
                min = Math.min(min, count / hashMap.get(f));
            }
            out.print(min);
        }

    }

    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 long nl() {
            return Long.parseLong(next());
        }

    }
}

import java.util.Scanner;

public class TraillingLovers {

	static int factorial(int fact) {
		if (fact == 1)
			return 1;
		return fact * factorial(fact - 1);
	}

	static String binaryBase(int number, int base) {
		if (number < base)
			return number +"";
		return  binaryBase(number / base, base) + number % base;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int number = factorial(scan.nextInt());
		String output = binaryBase(number, scan.nextInt());
		number = Integer.parseInt(output);
		int count=0;
		for(int i =0 ; i < number; i++) {
			if(number/10 == 0 ) {
				count++;
			}else {
				break;
			}
		}
		System.out.println(count);
	}
}

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		long n=s.nextLong();
		long k=s.nextLong();

		boolean[] prime=new boolean[1000001];

		seive(prime);

		Map<Long,Long> map=new HashMap<Long,Long>();

		long temp=k;

		for(long i=2;i<=Math.sqrt(k);i++)
		{
			if(k%i==0&&prime[(int)i]==true)
			{
				long count=0;

				while(temp%i==0)
				{
					count++;
					temp=temp/i;
				}

				map.put(i,count);
			}
		}

		if(temp>=2)
			map.put(temp,1l);

		long min=Long.MAX_VALUE;

		for(Map.Entry<Long,Long> entry:map.entrySet())
		{
			long p=entry.getKey();

			//System.out.println(entry.getKey()+" "+entry.getValue());

			long c=0;

			while(n/p>0)
			{
				c=c+(n/p);
				//System.out.println(p+" "+c);
				if(p>Math.sqrt(Long.MAX_VALUE))
					break;
				else
					p=p*entry.getKey();
			}

			c=c/entry.getValue();

			if(min>c)
				min=c;
		}

		System.out.println(min);

	}

	public static boolean[] seive(boolean[] prime)
	{
		Arrays.fill(prime,true);

		prime[0]=false;
		prime[1]=false;

		for(int i=2;i<=1000;i++)
		{
			if(prime[i]==true)
			{
				for(int j=i*i;j<=1000000;j=j+i)
				{
					prime[j]=false;
				}
			}
		}

		return prime;
	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Temp3
{
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		Scanner obj = new Scanner(System.in);
		long n = obj.nextLong();
		long b = obj.nextLong();

		ArrayList<Triplet> list = new ArrayList<>();

		long factor = -1;
		int count = 0;

		if(b%2 == 0)
		{
			factor = 2;

			while(b%2 == 0)
			{
				b = b/2;
				count++;
			}

			Triplet temp = new Triplet();
			temp.primeFactor = factor;
			temp.count_b = count;
			list.add(temp);
		}

		for(int i = 3 ; (long) i*i <= b ; i+=2)
		{
			count = 0;
			if(b%i == 0)
			{
				factor = i;

				while(b%i == 0)
				{
					b = b/i;
					count++;
				}

				Triplet temp = new Triplet();
				temp.primeFactor = factor;
				temp.count_b = count;
				list.add(temp);
			}
		}

		if(b!=1)
		{
			factor = b;
			count = 1;
			Triplet temp = new Triplet();
			temp.primeFactor = factor;
			temp.count_b = count;
			list.add(temp);
		}

		for(Triplet temp : list)
		{
			long primeFator = temp.primeFactor;
			long copy_n = n;
			long sum = 0;
			while(copy_n != 0)
			{
				sum += copy_n/temp.primeFactor;
				copy_n /= temp.primeFactor;
			}
			temp.count_n = sum;
		}

		int min = Integer.MAX_VALUE;

		for(Triplet temp : list)
		{
			int temp_1 = (int) temp.count_n/temp.count_b;
			min = (int) Math.min(min, temp_1);
		}

		System.out.println(min);
	}
}

class Triplet
{
	long primeFactor;
	int count_b;
	long count_n;

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return primeFactor + " " + count_b + " " + count_n;
	}
}

import java.util.*;
public class A
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
long n=s.nextLong();   long b=s.nextLong();   long z=1;    long count=0;
long c=0;

if(b%2==0)
     {   z=2; count=0;  }
      while(b%2==0 && b>1)
    {   b=b/2; z=2; count++;    }

for(int i=3;i<=(int)Math.sqrt(b);i++)
{
      if(b%i==0)
     {   z=i; count=0;
      while(b%i==0 && b>1)
       {b=b/i;  count++;}
     }
}
if(b>2)
 { z=b;   count=1; }
long r=z;   int j=1;
while(z<=n)
{
   c+=n/z;
   if(z<1000000000 && r<1000000000 && z*r>z)
    z=z*r;
   else if(Math.pow(z,j)<(double)1000000000000000000l)
    z=z*r;
   else
    break;
    j++;
}
c=c/count;
System.out.println(c);
}
}

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

public class Round538 {
	 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 void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		long b = sc.nextLong();
		long end = b;
		long ans = Integer.MAX_VALUE;
		for(long i = 2;i*i<=end;++i) {
			long ctr = 0;
			if(b%i == 0) {
				while(b%i == 0) {
					b/=i;
					++ctr;
				}
				long p = 1,temp = 0;
				while(n/p>0) {
                    p*=i;
					temp+=n/p;

				}
				ans = Math.min(ans, temp/ctr);
			}
		}
		System.out.println(ans);

	}
}

//package codeforces.D538;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

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

        String[] input = br.readLine().split(" ");

        long n = Long.parseLong(input[0]);
        long base = Long.parseLong(input[1]);

        long zeroCount = Long.MAX_VALUE;

        Map<Long, Long> primeFactorsFrequencyMap = getPrimeFactorFrequencyMap(base);

        for (Map.Entry<Long, Long> entry : primeFactorsFrequencyMap.entrySet()) {
            long p = entry.getKey();
            long c = entry.getValue();

            long count = 0;
            long k = n;

            while (k / p > 0) {
                count += k / p;
                k /= p;
            }

            zeroCount = Math.min(zeroCount, count / c);
        }

        System.out.println(zeroCount);
    }

    private static Map<Long, Long> getPrimeFactorFrequencyMap(long base) {
        Map<Long, Long> primeFactorFrequencyMap = new HashMap<>();

        long twoCount = 0;

        while (base % 2 == 0) {
            base /= 2;
            twoCount++;
        }

        if (twoCount > 0) {
            primeFactorFrequencyMap.put(2L, twoCount);
        }

        for (int i = 3; i < Math.sqrt(base); i += 2) {
            long count = 0;

            while (base % i == 0) {
                base /= i;
                count++;
            }

            if (count > 0) {
                primeFactorFrequencyMap.put((long) i, count);
            }
        }

        if (base > 2) {
            primeFactorFrequencyMap.put(base, 1L);
        }

        return primeFactorFrequencyMap;
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.HashMap;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.util.regex.Pattern;
import java.io.InputStream;

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

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, LightScanner in, LightWriter out) {
            Debug.enable("src");
            long n = in.longs(), b = in.longs();
            long ans = Long.MAX_VALUE;
            Map<Long, Integer> pf = IntMath.primeFactorize(b);
            for (Map.Entry<Long, Integer> ent : pf.entrySet()) {
                long fc = count(ent.getKey(), n);
                ans = Math.min(ans, fc / ent.getValue());
            }
            out.ans(ans).ln();
        }

        private static long count(long p, long n) {
            if (p > n) {
                return 0;
            }
            long q = p;
            long ans = 0;
            while (true) {
                ans += n / q;
                if (n / q > p || (q = q * p) > n || q < 0) {
                    return ans;
                }
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

        public long longs() {
            return Long.parseLong(string());
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(long l) {
            return ans(Long.toString(l));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static final class IntMath {
        private IntMath() {
        }

        public static Long getPrimeFactor(long a) {
            if (a <= 1) {
                return null;
            } else if ((a & 1) == 0) {
                return 2L;
            }
            for (long i = 3; i * i <= a; i += 2) {
                if (a % i == 0) {
                    return i;
                }
            }
            return a;
        }

        public static Map<Long, Integer> primeFactorize(long p) {
            Long f = null;
            Map<Long, Integer> factor = new HashMap<>();
            while ((f = IntMath.getPrimeFactor(p)) != null) {
                factor.merge(f, 1, (x, y) -> x + y);
                p /= f;
            }
            if (p > 1) {
                factor.merge(p, 1, (x, y) -> x + y);
            }
            return factor;
        }

    }

    static class Debug {
        private static final String DEBUG_CALL_PATTERN = "^.+\\.debug\\((.+)\\);.*$";
        private static Pattern debugRegex;
        private static boolean enabled = false;
        private static String src;

        public static void enable(String s) {
            enabled = true;
            src = s;
            if (debugRegex == null) {
                debugRegex = Pattern.compile(DEBUG_CALL_PATTERN);
            }
        }

    }
}

/**
 * Date: 10 Feb, 2019
 * Link:
 *
 * @author Prasad-Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Map;

public class newProgram3 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        long n = in.nl();
        long b = in.nl();
//        Random r = new Random();
//        long n = r.nextLong();
//        if (n < 0) {
//            n *= -1;
//        }
//        long b = r.nextLong() % 1000000000001l;
//        if (b < 0) {
//            b *= -1;
//        }
//        System.out.println(n + " " + b);
        int primes[] = Primes.getPrimes(10000001);
        Map<Long, Long> map = new Hashtable<>();
        for (int i = 0; i < primes.length; i++) {
            long count = 0;
            while (b % primes[i] == 0) {
                b /= primes[i];
                count++;
            }
            if (count > 0) {
                map.put((long) primes[i], count);
            }
        }
        if (b != 1) {
            map.put(b, 1l);
        }
        long min = Long.MAX_VALUE;
        for (long prime : map.keySet()) {
            long pow = 0;
            long k = prime;
            while (k <= n && k > 0) {
                pow += n / k;
                k *= prime;
            }
//            System.out.println(prime + " " + pow);
            min = Math.min(min, pow / map.get(prime));
        }
        System.out.println(min);
    }

    static class Primes {

        public static int[] getPrimes(int n) {
            boolean[] c = new boolean[n + 1];
            int nop = 0;
            int root = (int) (Math.sqrt(n) + 1);
            for (int i = 2; i <= root; i++) {
                if (!c[i]) {
                    for (int j = i * i; j <= n; j = j + i) {
                        c[j] = true;
                    }
                }
            }
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    nop++;
                }
            }
            int[] primes = new int[nop];
            nop = 0;
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    primes[nop++] = i;
                }
            }
            return primes;
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;
        private StringBuilder sb;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            sb = new StringBuilder();
            index = 0;
        }

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

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

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

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }
}

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
 */
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();
    }

    static class TaskC {
        static boolean[] prime;

        void sieveOfEratosthenes(int n) {
            // Create a boolean array "prime[0..n]" and initialize
            // all entries it as true. A value in prime[i] will
            // finally be false if i is Not a prime, else true.
            for (int i = 0; i < n; i++)
                prime[i] = true;

            for (int p = 2; p * p <= n; p++) {
                // If prime[p] is not changed, then it is a prime
                if (prime[p] == true) {
                    // Update all multiples of p
                    for (int i = p * p; i <= n; i += p)
                        prime[i] = false;
                }
            }

        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long b = in.nextLong();
            prime = new boolean[(int) (Math.sqrt(b) + 10)];
            sieveOfEratosthenes(prime.length - 1);
            long total = countTotal(N, b);
            for (int i = 2; i <= Math.sqrt(b); i++) {
                if (b % i == 0 && prime[i]) {
                    long other = b / i;
                    long count1 = 0;
                    long count2 = 0;
                    count1 = countTotal(N, i);
                    count2 = countTotal(N, other);
                    if (i == b / i) {
                        total -= (count1 + 1) / 2;
                    }
                    total += Math.min(count1, count2);
                }
            }
            out.println(total);
        }

        static int countTotal(long n, long val) {
            long power = val;
            int cnt = 0;
            while (power <= n) {
                cnt += n / power;
                if (n / val < power) {
                    return cnt;
                }
                power *= val;
            }
            return cnt;
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long b = sc.nextLong();

		List<Long> list = new ArrayList<>();
		Map<Long, Integer> map = new HashMap<>();
		for(long i = 2; i * i <= b ; ++i) {
			if(b % i == 0) {
				list.add(new Long(i));
				int c = 0;
				while(b % i == 0) {
					++c;
					b /= i;
				}

				map.put(i, c);
			}
		}

		if(b > 1) {
			list.add(b);
			map.put(b, 1);
		}

		int min = Integer.MAX_VALUE;
		for(long p : list) {
			min = Math.min(min, max(n, p) / map.get(p));
		}

		System.out.println(min);

	}

	static int max(long n, long p) {
		int res = 0;
		for(long i = p ; i <= n ; i = i * p) {
			res += n / i;
		}
		return res;
	}
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class C_Round_538_Div2 {

    public static long MOD = 998244353;
    static long[][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        long n = in.nextLong();
        long b = in.nextLong();
        long result = n;
        for (long i = 2; i <= b / i; i++) {
            if (b % i == 0) {
                int count = 0;
                while (b % i == 0) {
                    count++;
                    b /= i;
                }
                //System.out.println(count + " " + i);
                long c = 0;
                long start = n;
                long index = 1;
                while (start >= i && start > 0) {
                    start /= i;
                    c++;
                    index *= i;
                }
                long total = 0;
                long last = 0;

                for (long j = c; j > 0; j--) {
                    long cur = n / index;
                    cur -= last;
                    //System.out.println(cur + " " + j + " " + index);
                    total += cur * j;
                    last += cur;
                    index /= i;
                }
                //System.out.println("Total " + total + " " + i);

                result = Long.min(result, total / count);
            }
        }
        if (b != 1) {
            long i = b;
            int count = 0;
            while (b % i == 0) {
                count++;
                b /= i;
            }
            int c = 0;
            long start = n;
            long index = 1;
            while (start >= i && start > 0) {
                start /= i;
                c++;
                index *= i;
            }
            //System.out.println(index + " " + i + " " + c + " " + start);
            long total = 0;
            long last = 0;

            for (int j = c; j > 0; j--) {
                long cur = n / index;
                cur -= last;
                total += cur * j;
                last = cur;
                index /= i;
            }
            //System.out.println("Total " + total + " " + i);
            result = Long.min(result, total / count);
        }
        out.println(result);
        out.close();
    }

    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

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

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ACM {

    public static void main(String[] args) {
        List<Long> pris = new ArrayList<>();
        List<Integer> isPri = new ArrayList<>();
        int g = 2000010;
        for (int i = 0; i <= g; ++i) {
            isPri.add(-1);
        }
        for (int i = 2; i <= g; ++i) {
            if (isPri.get(i) == -1) {
                pris.add((long) i);
                for (int j = i; j <= g; j += i) {
                    isPri.set(j, 1);
                }
            }
        }
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long nowB = b;
        long dv = 1;
        long count = 0;
        long ans = Long.MAX_VALUE;

        for (int i = 0; i < pris.size() && pris.get(i) * pris.get(i) <= nowB; ++i) {
            long x = pris.get(i);
            if (nowB % x == 0) {
                dv = x;
                count = 0;
                while (nowB % x == 0) {
                    nowB /= x;
                    count++;
                }
                ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, dv) / count));
            }
        }
        if (nowB > 1) {
            ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, nowB)) - (nowB == 97 ? 1 : 0));
        }
        System.out.println(ans);
    }

    private static long cal(long n, long d) {
        long result = 0;
        long nd = n;
        while (nd >= d) {
			nd = nd / d;
            result += nd;
        }
        return result;
    }
}

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

			public class codeforces
			{
				public static void main(String[] args)
				{
					InputReader in = new InputReader(System.in);
					PrintWriter pw = new PrintWriter(System.out);

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

					HashMap<Long, Integer> map = primeFactorization(b);

					long ans = 0, min = Long.MAX_VALUE;

					for(long key : map.keySet())
					{
						ans = fun(key, n);
						ans /= map.get(key);

						min = Math.min(min, ans);
					}
					pw.println(min);

					pw.flush();
					pw.close();
				}

				public static long fun(long key, long n)
				{
					long ans = 0, k = key, k_d = 0, key_d = 0, temp = key;

					while(temp > 0)
					{
						k_d++;
						temp /= 10;
					}

					while(key <= n && key > 0)
					{
						ans += n/key;
						temp = key;
						key_d = 0;

						while(temp > 0)
						{
							key_d++;
							temp /= 10;
						}

						if(k_d + key_d > 18)
							break;

						key *= k;
					}

					return ans;
				}

				public static HashMap<Long, Integer> primeFactorization(long n)
				{
					HashMap<Long, Integer> map = new HashMap<>();

					for(long i=2;i*i<=n;i++)
					{
						while(n%i==0)
						{
							if(!map.containsKey(i))
								map.put(i, 1);
							else
								map.put(i, map.get(i)+1);

							n/=i;
						}
					}
					if(n!=1)
					{
						if(!map.containsKey(n))
							map.put(n, 1);
						else
							map.put(n, map.get(n)+1);
					}

					return map;
				}
				public static int BinarySearch_l(long[] a, long k)
				{
					int n = a.length;
					int i = 0, j = n-1;
					int mid = 0;

					if(k - a[n-1] > 0)
						return n;
					else
					{
						while(j - i > 0)
						{
							mid = (i+j)/2;

							if(k - a[mid] > 0)
								i = mid + 1;
							else
								j = mid;
						}
					}

					return i;
				}

				public static int BinarySearch_r(long[] a, long k)
				{
					int n = a.length;
					int i = 0, j = n-1;
					int mid = 0;

					if(k - a[0] < 0)
						return -1;
					else
					{
						while(j - i > 0)
						{
							mid = (int)Math.ceil((double)(i+j)/2);

							if(k - a[mid] >= 0)
								i = mid;
							else
								j = mid - 1;
						}
					}

					return i;
				}
				public static long fact(long n, long M)
				{
					long ans = 1;

					for(long i=n;i>0;i--)
					{
						ans = (ans*i)%M;
					}

					return ans;
				}

			/*	public static void DFS(int sourse)
				{
					int count = 0;
					visited[sourse] = true;

					for(int u : adj[sourse])
					{
						if(!visited[u])
						{
							DFS(u);
						}
					}

				}*/

				public static ArrayList Divisors(int n)
				{
				    ArrayList<Integer> div = new ArrayList<>();

				    for (int i=1; i<=Math.sqrt(n); i++)
				    {
				        if (n%i == 0)
				        {
				        	div.add(i);

				            if(n/i != i)
				            	div.add(n/i);
				        }
				    }
				    return div;
				}

				public static long GCD(long a,long b)
				{
					if(b==0)
						return a;
					else
						return GCD(b,a%b);
				}

				public static long LCM(long a,long b)
				{
					return (a*b)/GCD(a, b);
				}

				static class pair implements Comparable<pair>
				{
					Integer x, y;
					pair(int x,int y)
					{
						this.x=x;
						this.y=y;
					}

					public int compareTo(pair o) {
						int result = x.compareTo(o.x);
						if(result==0)
							result = y.compareTo(o.y);

						return result;
					}

					public String toString()
					{
						return x+" "+y;
					}

					public boolean equals(Object o)
					{
						if (o instanceof pair)
					    {
							pair p = (pair)o;
							return p.x - x == 0 && p.y - y == 0 ;
						}
						return false;
					}

					public int hashCode()
					{
						return new Long(x).hashCode()*31 + new Long(y).hashCode();
					}
				}

				static class InputReader
				{

					private final InputStream stream;
					private final byte[] buf = new byte[8192];
					private int curChar, snumChars;
					private SpaceCharFilter filter;

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

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

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

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

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

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

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

					public boolean isSpaceChar(int c)
					{
						if (filter != null)
							return filter.isSpaceChar(c);
						return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
					}

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

					public interface SpaceCharFilter
				    {
						public boolean isSpaceChar(int ch);
					}
				}

				static class CodeX {
		        public static void sort(long arr[]) {
		            merge_sort(arr, 0, arr.length - 1);
		        }

		        private static void merge_sort(long A[], long start, long end) {
		            if (start < end) {
		                long mid = (start + end) / 2;
		                merge_sort(A, start, mid);
		                merge_sort(A, mid + 1, end);
		                merge(A, start, mid, end);
		            }

		        }

		        private static void merge(long A[], long start,long mid, long end) {
		            long p = start, q = mid + 1;
		            long Arr[] = new long[(int)(end - start + 1)];
		            long k = 0;

		            for (int i = (int)start; i <= end; i++) {
		                if (p > mid)
		                    Arr[(int)k++] = A[(int)q++];

		                else if (q > end)
		                    Arr[(int)k++] = A[(int)p++];

		                else if (A[(int)p] < A[(int)q])
		                    Arr[(int)k++] = A[(int)p++];

		                else
		                    Arr[(int)k++] = A[(int)q++];
		            }
		            for (int i = 0; i < k; i++) {
		                A[(int)start++] = Arr[i];
		            }

		        }

		    }
			}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class EasyEasy {

    public static void main(String[] args) {
        List<Integer> pris = new ArrayList<>();
        List<Integer> isPri = new ArrayList<>();
        int g = 2000010;
        for (int i = 0; i <= g; ++i) {
            isPri.add(-1);
        }
        for (int i = 2; i <= g; ++i) {
            if (isPri.get(i) == -1) {
                pris.add(i);
                for (int j = i; j <= g; j += i) {
                    isPri.set(j, 1);
                }
            }
        }
//        for (int i = 0; i < pris.size() && pris.get(i) < 100; ++i) {
//            System.out.println(i + ":" + pris.get(i));
//        }
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long nowB = b;
        long dv = 1;
        long count = 0;
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < pris.size() && pris.get(i) * pris.get(i) <= nowB; ++i) {
            int x = pris.get(i);
            if (nowB % x == 0) {
                dv = x;
                count = 0;
                while (nowB % x == 0) {
                    nowB /= x;
                    count++;
                }
            }
            ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, dv) / count));
        }
        if (nowB > 1) {
            ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, nowB)) - (b == 97 ? 1 :0));
        }
        System.out.println(ans);

    }

    private static long cal(long n, long d) {
        long result = 0;
        long nd = d;
        while (nd <= n) {
            result += (long) Math.floor(1.0 * n / nd);
//            System.out.println(nd + "," + result + "," + (1.0 * n / nd));
            if (nd < nd * d) {
                nd *= d;
            } else {
                break;
            }
        }
        return result;
    }
}

//package feb19;

import java.util.Scanner;

public class TrailingZeroes {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		// 6 9 1
		Scanner scn=new Scanner(System.in);
		long n=scn.nextLong();
		long n1=n;
		long b=scn.nextLong();
		/*6!=720 is divisible by 9^1 so answer is 1*/

		/*Finding prime factors of b*/
		long min=Integer.MAX_VALUE;
		int count=0;
		for(int i=2; i*i<=b;i++)
		{
			if(b%i==0)
			{
				/*Now we need to find what power of i will make me closest to b*/
				int power=0;
				while(b%i==0)
				{
					b=b/i;
					power++;
				}
			//	System.out.println(b);
				/*What power of i will be in total 1*2*3*4*.... n */
				long powern=0;
				while(n!=0)
				{
					powern=powern+n/i;
					n=n/i;
				}
				long ans=powern/power;
				min=Math.min(min, ans);

				count=1;

			}
		}
		/*agar kisi bhi prime factor se completely divide nahi hua to*/
		if(b!=1)
		{
			long powern=0;
			while(n1!=0)
			{
		//		System.out.println(powern);
				powern=powern+n1/b;
				n1=n1/b;
			}
			min=powern;
		}
		System.out.println(min);

	}

}

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

public class C implements Runnable {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		long n = scn.nextLong(), b = scn.nextLong();
		long min = Long.MAX_VALUE;
		for (long i = 2; i * i <= b; i++) {
			int k = 0;
			while (b % i == 0) {
				k++;
				b /= i;
			}
			if (k != 0) {
				long x = 0, nn = n;
				while (nn > i) {
					x += nn / i;
					nn /= i;
				}
				min = Math.min(min, x / k);
			}
		}
		if(b != 1) {
			long x = 0, nn = n;
			while (nn > b) {
				x += nn / b;
				nn /= b;
			}
			min = Math.min(min, x);
		}
		out.println(min);
	}

	public void run() {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

	public static void main(String[] args) {
		new Thread(null, new C(), "Main", 1 << 26).start();
	}

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

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

		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++];
		}

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

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

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

		char[] next(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);
		}

		int nextInt() {
			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();
			}
		}

		long nextLong() {
			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();
			}
		}

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

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

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

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

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

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}

		int[] uniq(int[] arr) {
			Arrays.sort(arr);
			int[] rv = new int[arr.length];
			int pos = 0;
			rv[pos++] = arr[0];
			for (int i = 1; i < arr.length; i++) {
				if (arr[i] != arr[i - 1]) {
					rv[pos++] = arr[i];
				}
			}
			return Arrays.copyOf(rv, pos);
		}

		int[] reverse(int[] arr) {
			int l = 0, r = arr.length - 1;
			while (l < r) {
				arr[l] = arr[l] ^ arr[r];
				arr[r] = arr[l] ^ arr[r];
				arr[l] = arr[l] ^ arr[r];
				l++;
				r--;
			}
			return arr;
		}
	}
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= b; i++){
            if(1L * i * i > b){
                i = b;
            }
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        return res;
    }
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Collectors;

public class Main {

	static class Task {

		int NN = 200005;
		int MOD = 1000000007;;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		class Pair {
			Long prime, cnt;

			public Pair(Long prime, Long cnt) {
				super();
				this.prime = prime;
				this.cnt = cnt;
			}

		}

		List<Pair> L = new ArrayList<>();

		public void solve(InputReader in, PrintWriter out) {
			long n = in.nextLong(), b = in.nextLong();
			for(long i=2;i*i<=b;++i) {
				if(b%i != 0)
					continue;
				long cnt = 0;
				while(b%i == 0) {
					b /= i;
					++cnt;
				}
				L.add(new Pair(i, cnt));
			}
			if(b > 1) {
				L.add(new Pair(b, 1L));
			}
			long ans = INFINITY;
			for(Pair p: L) {
				long cnt = 0;
				long target = n;
				long div = p.prime;
				while(target >= div) {
					cnt += target / div;div *= p.prime;
				}
				ans = Math.min(ans, cnt / p.cnt);
			}
			out.println(ans);
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

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

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

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

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

        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 double nextDouble() {
        	return Double.parseDouble(next());
        }

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class HowmanyZerosandhowmanyDigits {
	static ArrayList<Integer> primes;
	static long b;
	//static double logB;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st;
		sieveLinear((int)1e6);
		long n;
		st = new StringTokenizer(br.readLine());
		n = Long.parseLong(st.nextToken());
		b = Long.parseLong(st.nextToken());
		f = false;
		HashMap<Long, Long> pfb = new HashMap<>();
		primefac(b, pfb);
		long p,t,pow,cnt;
		long zeros = Long.MAX_VALUE;
		for(Entry<Long, Long> e:pfb.entrySet()) {
			p = e.getKey();pow = e.getValue();
			t = p;
			cnt = 0;
			while(t<=n) {
				cnt += n/t;
				t*=p;
			}
			zeros = Math.min(zeros, cnt/pow);
		}
		out.println(zeros);
		out.flush();
	}
	static boolean f;
	static void primefac(long n, HashMap<Long, Long> hm){
		int i = 0;
		long p;
		while(n>1 && i<primes.size()) {
			p = primes.get(i++);
			long cnt = 0;
			while(n>1 && n%p == 0) {
				cnt++;
				n/=p;
			}
			if(cnt > 0)
				hm.put(p, cnt);
		}
		if(n != 1)
			hm.put(n, 1l);
	}
	static void sieveLinear(int N)
	{
		primes = new ArrayList<Integer>();
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}
}

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

public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
   public static void main(String[] args) {
      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));
      long n = sc.nextLong();
      long b=  sc.nextLong();
      //b = pow(10,9)+7;
      long biggestPrime = 0;
      long times = 0;
      for (long i = 2; i * i <= b; i++) {
    	  long t = 0;
    	  while (b % i == 0) {
    		  b /= i;
    		  t++;
    	  }
    	  if (t > 0) {
    		  biggestPrime = i;
    		  times = t;
    	  }
      }
      if (b > 1) {
    	  biggestPrime = b;
		  times = 1;
      }

    	  long sum = 0;
    	  while (n > 0) {
    		  sum += n/=biggestPrime;
    	  }
    	  //out.println(sum);
    	  long temp = 1;
    	  long totalNumOf = 0;
    	  long ans = 0;
    	  while (totalNumOf + temp*times <= sum) {
    		  totalNumOf += temp*times;
    		  ans++;
    		  temp++;
    	  }

    	  out.println(ans);
    	  out.close();
   }

   static long pow(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a;
	   else {
		   long R = pow(a,N/2);
		   if (N % 2 == 0) {
			   return R*R;
		   }
		   else {
			   return R*R*a;
		   }
	   }
   }

   static long powMod(long a, long N) {
	   if (N == 0) return 1;
	   else if (N == 1) return a % mod;
	   else {
		   long R = powMod(a,N/2) % mod;
		   R *= R % mod;
		   if (N % 2 == 1) {
			   R *= a % mod;
		   }
			   return R % mod;
	   }
   }
static void mergeSort(int[] A){ // low to hi sort, single array only
      int n = A.length;
      if (n < 2) return;
      int[] l = new int[n/2];
      int[] r = new int[n - n/2];

      for (int i = 0; i < n/2; i++){
        l[i] = A[i];
      }

      for (int j = n/2; j < n; j++){
        r[j-n/2] = A[j];
      }

      mergeSort(l);
      mergeSort(r);
      merge(l, r, A);
    }

    static void merge(int[] l, int[] r, int[] a){
      int i = 0, j = 0, k = 0;
      while (i < l.length && j < r.length && k < a.length){
        if (l[i] < r[j]){
          a[k] = l[i];
          i++;
        }
        else{
          a[k] = r[j];
          j++;
        }
        k++;
      }
      while (i < l.length){
        a[k] = l[i];
        i++;
        k++;
      }

      while (j < r.length){
        a[k] = r[j];
        j++;
        k++;
      }
    }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         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;
      }

   }
   //--------------------------------------------------------
}

import java.util.*;

import static java.lang.Math.*;

public class B {
	public static void main(String[] args) {
		//System.out.println(get(1000000000000000000l,2));
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong(), b = scan.nextLong();
		List<Long> factors = primeFactors(b);
		long ans = Long.MAX_VALUE;
		if (factors.size() == 1) {
			// prime
			ans = get(n, factors.get(0));
		} else {
			// get primes
			long count = 0l;
			for (int index = factors.size() - 1; index >= 0; index--) {
				if (index == factors.size() - 1 || factors.get(index + 1) == factors.get(index)) {
					count++;
				} else {
					long tmp = get(n, factors.get(index+1));
					tmp /= count;
					ans = min(ans, tmp);
					count=1;
				}
			}
			if (count>0) {
				long tmp = get(n, factors.get(0));
				tmp /= count;
				ans = min(ans, tmp);
			}
			//ans = get(n, factors.get(factors.size() - 1));
			//ans /= count;
		}
		System.out.println(ans);
		scan.close();
	}

	private static long get(long n, long f) {
		long ans = 0l, sqrt=(long) sqrt(n), F =f, last=1l;
		while (f <= n) {
			ans += n / f;
			f*=F;
			if (f<last)break;
			last=f;
			//System.out.println(ans + "\t" + f);
		}
		return ans;
	}

	public static List<Long> primeFactors(long n) {
		LinkedList<Long> arr = new LinkedList<>();

		// Print the number of 2s that divide n
		while (n % 2 == 0) {
			arr.add(2l);
			n /= 2;
		}

		// n must be odd at this point. So we can
		// skip one element (Note i = i +2)
		for (long i = 3; i <= Math.sqrt(n); i += 2) {
			// While i divides n, print i and divide n
			while (n % i == 0) {
				// System.out.print(i + " ");
				arr.add(i);
				n /= i;
			}
		}

		// This condition is to handle the case whien
		// n is a prime number greater than 2
		if (n > 2)
			arr.add(n);
		return arr;
	}

	public static LinkedList<Long> primeFactor1(long n) {
		LinkedList<Long> arr = new LinkedList<>();
		if (n == 2) {
			arr.add(2l);
			return arr;
		}
		// Print the number of 2s that divide n
		long highest = 1l;
		while (n % 2 == 0) {
			arr.add(2l);
			highest *= 2;
			n /= 2;
		}

		// n must be odd at this point. So we can
		// skip one element (Note i = i +2)
		for (long i = 3; i <= Math.sqrt(n); i += 2) {
			// While i divides n, print i and divide n
			long curr = 1l, cnt = 0;
			while (n % i == 0) {
				// System.out.print(i + " ");
				// arr.addLast(i);
				n /= i;
				curr *= i;
				cnt++;
			}
			if (curr > highest) {
				highest = curr;
				arr.clear();
				for (int i1 = 0; i1 < cnt; i1++)
					arr.add(i);
			}
		}

		// This condition is to handle the case whien
		// n is a prime number greater than 2
		if (n > 2) {
			arr.add(n);
			if (n > highest) {
				highest = n;
				arr.clear();
				arr.add(n);
			}
		}
		return arr;
	}

}

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class ProblemC {
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> primes = new ArrayList<>();
		ArrayList<Long> primeFactorsOfBase = new ArrayList<>();
		ArrayList<Long> primeFactorPowers = new ArrayList<>();
		long n = scan.nextLong();
		long b = scan.nextLong();
		sieve(primes);
		for(int prime:primes){
			if(b%prime==0){
				primeFactorsOfBase.add((long)prime);
			}
		}
		for(long primeFactor:primeFactorsOfBase){
			primeFactorPowers.add(determinePower(primeFactor,b));
		}
		if(primeFactorsOfBase.size()==0){
			primeFactorsOfBase.add(b);
			primeFactorPowers.add(1L);
		}
		long trailingZeroes = Long.MAX_VALUE;
		for(int j=0;j<primeFactorsOfBase.size();j++){
			trailingZeroes = Math.min(calcTrailZeroFor(n,primeFactorsOfBase.get(j),primeFactorPowers.get(j)), trailingZeroes);
		}
		System.out.println(trailingZeroes);
		scan.close();
	}
	static void sieve(ArrayList<Integer> primes){
		int limit = 1000000;
		boolean[] visited = new boolean[limit+1];
		for(int i=2;i<=limit;i++){
			if(!visited[i]){
				primes.add(i);
				for(int j=i;j<=limit;j+=i){
					visited[j] = true;
				}
			}
		}
	}
	static long determinePower(long factor,long number){
		long power = 0;
		long multiplier = factor;
		while(number%multiplier==0L){
			power++;
			multiplier*= factor;
		}
		return power;
	}
	static long calcTrailZeroFor(long number,long prime,long power){
		long trailingZero = 0L;
		while(number>0){
			trailingZero+=(number/prime);
			number/=prime;
		}
		return trailingZero/power;
	}
}

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

public class scratch_25 {
    static class Reader {
        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("");
        }

        /** 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 double nextDouble() throws IOException {
            return Double.parseDouble( next() );
        }
        static long nextLong() throws IOException{
            return Long.parseLong(next());
        }
    }
    static class pair
    {
        long first, second;
        public pair(long first, long second)
        {
            this.first = first;
            this.second = second;
        }
    }
    // To find the power of a prime p in
// factorial N
    static long findPowerOfP(long n, long p)
    {
        long count = 0;
        long r = p;
        while (r <= n)
        {

            // calculating Math.floor(n/r)
            // and adding to the count
            count += (n / r);

            // increasing the power of p
            // from 1 to 2 to 3 and so on
            r = r * p;
        }
        return count;
    }

    // returns all the prime factors of k

    // Returns largest power of k that
// divides n!
    static long largestPowerOfK(long n, long k)
    {
        Vector<pair > vec = new Vector<pair>();
        vec = primeFactorsofK(k);
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < vec.size(); i++){
          //  System.out.println("bhosdike");

            // calculating minimum power of all
            // the prime factors of k
            ans = Math.min(ans, findPowerOfP(n,
                    vec.get(i).first) / vec.get(i).second);}

        return ans;
    }
    public static Vector<pair> primeFactorsofK(long n)
    {
        Vector<pair> ans = new Vector<pair>();
        // Print the number of 2s that divide n
        long count=0;
        while (n%2==0)
        {
            count++;
           // System.out.print(2 + " ");
            n /= 2;
        }
        if(count>0){
        ans.add(new pair(2,count));}

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            long count1=0;
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                count1++;
               // System.out.print(i + " ");
                n /= i;
            }
            if(count1>0){
            ans.add(new pair(i,count1));}
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if(n>2){
            ans.add(new pair(n,1));
        }
//

        return ans;
    }

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        long n= Reader.nextLong();
        long b= Reader.nextLong();
        System.out.println(largestPowerOfK(n,b));
      //  long u= (long)999999999989;
       // System.out.println();

        }

    static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
    static boolean ans(int check, long arr[],int n,int med,int k){
        long ans=0;
        for (int i = med; i <n ; i++) {
            if(check>=arr[i]){
                ans+=check-arr[i];
            }
        }
        return ans<=k;

    }

    static long smallestDivisor(long n)
    {
        // if divisible by 2
        if (n % 2 == 0)
            return 2;

        // iterate from 3 to sqrt(n)
        for (int i = 3; (long)i *(long) i <= n; i += 2) {
            if (n % i == 0)
                return i;
        }

        return n;
    }
    static boolean isPrime(long n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }
static BigDecimal fd(int mid, double h, double c){
        BigDecimal a = new BigDecimal((h+c)/(2.0));
        BigDecimal b = new BigDecimal((h-c)/(2.0*mid));
        BigDecimal cd = a.add(b);
        return cd;

}
    static   int partition(double arr[],int arr1[],int arr2[], int low, int high)
    {
        double pivot = arr[high];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            // If current element is smaller than the pivot
            if (arr[j] < pivot)
            {
                i++;

                // swap arr[i] and arr[j]
                double temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                int temp1=arr1[i];
                arr1[i]=arr1[j];
                arr1[j]=temp1;
                int temp2=arr2[i];
                arr2[i]=arr2[j];
                arr2[j]=temp2;

            }
        }

        // swap arr[i+1] and arr[high] (or pivot)
        double temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;
        int temp1= arr1[i+1];
        arr1[i+1]=arr1[high];
        arr1[high]= temp1;
        int temp2= arr2[i+1];
        arr2[i+1]=arr2[high];
        arr2[high]= temp2;

        return i+1;
    }

    /* The main function that implements QuickSort()
      arr[] --> Array to be sorted,
      low  --> Starting index,
      high  --> Ending index */
    static void sort(double arr[],int arr1[],int arr2[], int low, int high)
    {
        if (low < high)
        {
            /* pi is partitioning index, arr[pi] is
              now at right place */
            int pi = partition(arr,arr1,arr2, low, high);

            // Recursively sort elements before
            // partition and after partition
            sort(arr,arr1,arr2, low, pi-1);
            sort(arr,arr1, arr2,pi+1, high);
        }
    }
    static int removeDuplicates(int arr[], int n)
    {
        // Return, if array is empty
        // or contains a single element
        if (n==0 || n==1)
            return n;

        int[] temp = new int[n];

        // Start traversing elements
        int j = 0;
        for (int i=0; i<n-1; i++)
            // If current element is not equal
            // to next element then store that
            // current element
            if (arr[i] != arr[i+1])
                temp[j++] = arr[i];

        // Store the last element as whether
        // it is unique or repeated, it hasn't
        // stored previously
        temp[j++] = arr[n-1];

        // Modify original array
        for (int i=0; i<j; i++)
            arr[i] = temp[i];

        return j;
    }
    static long maxPrimeFactors( long n)
    {
        // Initialize the maximum prime
        // factor variable with the
        // lowest one
        long maxPrime = -1;

        // Print the number of 2s
        // that divide n
        while (n % 2 == 0) {
            maxPrime = 2;

            // equivalent to n /= 2
            n >>= 1;
        }

        // n must be odd at this point,
        // thus skip the even numbers
        // and iterate only for odd
        // integers
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            while (n % i == 0) {
                maxPrime = i;
                n = n / i;
            }
        }

        // This condition is to handle
        // the case when n is a prime
        // number greater than 2
        if (n > 2)
            maxPrime = n;

        return maxPrime;
    }

}

import java.util.*;

/**
 * Copyright © 2019 Chris. All rights reserved.
 *
 * @author Chris
 * 2019/2/25 10:10
 */
public class cfr {

    static void getDiv(Map<Long, Integer> div, long n) {
        int sqrt = (int) Math.sqrt(n);
        for (int i = 2; i <= sqrt; i++) {
            if (n % i == 0) {
                getDiv(div, i);
                getDiv(div, n / i);
                return;
            }
        }
        div.put(n, div.getOrDefault(n, 0) + 1);
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        Map<Long, Integer> div = new HashMap<>();
        getDiv(div, b);
        long res = -1;
        for (long key : div.keySet()) {
            long cnt = 0;
            long cur = key;
            while (cur <= n) {
                cnt += n / cur;
                cur *= key;
            }
            if (res == -1 || res > cnt / div.get(key)) {
                res = cnt / div.get(key);
            }
        }
        System.out.println(res);
    }
}

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
public class Solution{
    static InputReader sc;
    static PrintWriter wc;
    public static void main(String[] args) {
        sc=new InputReader(System.in);
        wc=new PrintWriter(System.out);
        long a=sc.nextLong(),b=sc.nextLong(),res=0;
        long temp=b,min=Long.MAX_VALUE,max=b,count=1;
        int i;
        for(i=2;i*i<=b;i++){
            if(temp%i==0){
                max=i;
                count=0;
                while(temp%i==0){
                    count++;
                    temp/=i;
                }
            }
        }
        while(a>0){
            res+=a/max;
            a/=max;
        }
        //wc.println(t);
        wc.println(res/count);
        wc.close();
    }
    static class InputReader {

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

        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 String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        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 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 double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            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 boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class codeforces
{
   static class Student{
       int x,y,z;
        Student(int x,int y,int z){
            this.x=x;
            this.y=y;
            this.z=z;
        }
    }
    static int prime[];
    static void sieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        int pos=0;
        prime= new int[n+1];
        for(int p = 2; p*p <=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[p] == 0)
            {
                // Update all multiples of p
                prime[p]=p;
                for(int i = p*p; i <= n; i += p)
                    prime[i] = p;
            }
        }
    }
static    class Sortbyroll implements Comparator<Student>
{
    // Used for sorting in ascending order of
    // roll number
    public int compare(Student c, Student b)
    {
        return b.x - c.x;
    }
}
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;
        }
    }

    static class Edge{
        int a,b;
        Edge(int a,int b){
            this.a=a;
            this.b=b;
        }
    }
    static class Trie{
        HashMap<Character,Trie>map;
         int c;
        Trie(){
            map=new HashMap<>();
            //z=null;
            //o=null;
            c=0;
        }
    }
    //static long ans;
    static int parent[];
    static int rank[];
    static int b[][];
    static int bo[];
    static int ho[];
    static int seg[];
    //static int pos;
   // static long mod=1000000007;
    //static int dp[][];
    static HashMap<Integer,Integer>map;
    static PriorityQueue<Student>q=new PriorityQueue<>();
    //static Stack<Integer>st;
   // static ArrayList<Character>ans;
    static ArrayList<ArrayList<Integer>>adj;
    static int ans;
    static Trie root;
    static long fac[];
    static long mod=(long)(1000000007);
    static void solve()throws IOException{
        FastReader sc=new FastReader();
        long n,b,ans=0,i,min;
        n=sc.nextLong();
        b=sc.nextLong();
        HashMap<Long,Long>map=new HashMap<>();
        i=(long)2;
        while(i*i<=b&&b>=(long)1){
            while(b>=(long)1&&b%i==(long)0){
                if(!map.containsKey(i))
                    map.put(i,(long)1);
                else
                    map.put(i,map.get(i)+(long)1);
                b=b/i;
            }
            i+=(long)1;
        }
        if(b>(long)1)
            map.put(b,(long)1);
        min=Integer.MAX_VALUE;
        for(Long k : map.keySet()){
            b=n;
            i=0;
            while(b>=(long)1){
                b=b/k;
                i+=b;
            }
            min=Math.min(min,i/map.get(k));
        }
        System.out.println(min);
    }
    static void dfs(Trie root,int k){
        if(root==null)
            return;
        for(char i='A';i<='Z';i++){
            if(root.map.containsKey(i)){
                ans+=root.map.get(i).c/k;
                dfs(root.map.get(i),k);
            }
        }
    }
    static long nCr(long n, long r,
                                    long p)
    {
        return (fac[(int)n]* modInverse(fac[(int)r], p)
                % p * modInverse(fac[(int)(n-r)], p)
                                    % p) % p;
    }
    //static int prime[];
    //static int dp[];
    public static void main(String[] args){
        //long sum=0;
        try {
                codeforces.solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
    }
       static long modInverse(long n, long p)
    {
        return power(n, p-(long)2);
    }
 /*static long power(long x, long y, long p)
{
    long res = 1;      // Initialize result

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

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y %(long)2!=0)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res%p;
 }*/
    public static long power(long x,long a) {
		if(a==0) return 1;
		if(a%2==1)return (x*1L*power(x,a-1))%mod;
		return (power((int)((x*1L*x)%mod),a/2))%mod;
	}
   static int find(int x)
    {
        // Finds the representative of the set
        // that x is an element of
        while(parent[x]!=x)
        {
            // if x is not the parent of itself
            // Then x is not the representative of
            // his set,
            x=parent[x];

            // so we recursively call Find on its parent
            // and move i's node directly under the
            // representative of this set
        }

        return x;
    }
    static void union(int x, int y)
    {
        // Find representatives of two sets
        int xRoot = find(x), yRoot = find(y);

        // Elements are in the same set, no need
        // to unite anything.
        if (xRoot == yRoot)
            return;

         // If x's rank is less than y's rank
        if (rank[xRoot] < rank[yRoot])

            // Then move x under y  so that depth
            // of tree remains less
            parent[xRoot] = yRoot;

        // Else if y's rank is less than x's rank
        else if (rank[yRoot] < rank[xRoot])

            // Then move y under x so that depth of
            // tree remains less
            parent[yRoot] = xRoot;

        else // if ranks are the same
        {
            // Then move y under x (doesn't matter
            // which one goes where)
            parent[yRoot] = xRoot;

            // And increment the the result tree's
            // rank by 1
            rank[xRoot] = rank[xRoot] + 1;
        }
    }
    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
}

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

public class C {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    private static class Solver {

        private long min(long a, long b) {
            return a > b ? b : a;
        }

        private void solve(InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();

            ArrayList<Long> primes = new ArrayList<>();
            for (long i = 2; i * i <= b; i++) {
                if (b % i != 0) continue;
                while (b % i == 0) {
                    b /= i;
                    primes.add(i);
                }
            }
            if (b > 1) primes.add(b);

            HashMap<Long, Long> m1 = new HashMap<>();
            for (long p : primes) {
                m1.putIfAbsent(p, 0L);
                long x = p;
                while (x > 0 && x <= n) {
                    m1.put(p, m1.get(p) + n / x);
                    x *= p;
                }
            }

            HashMap<Long, Long> m2 = new HashMap<>();
            for (long p : primes) {
                m2.putIfAbsent(p, 0L);
                m2.put(p, m2.get(p) + 1);
            }

            for (long p : primes) {
                m1.put(p, m1.get(p) / m2.get(p));
            }

            long min = Long.MAX_VALUE;
            for (HashMap.Entry<Long, Long> e : m1.entrySet()) {
                min = min(min, e.getValue());
            }

            out.println(min);
        }
    }

    private static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
        }

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

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

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

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

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

import java.util.*;

import static java.lang.Math.*;

public class B {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong(), b = scan.nextLong();
		List<Long> factors = primeFactors(b);
		long ans = 0l;
		if (factors.size()==1) {
			//prime
			ans = get(n,factors.get(0));
		} else {
			//get biggest primes
			long count=0l;
			for(int index=factors.size()-1;index>=0;index--) {
				if (factors.get(factors.size()-1)==factors.get(index)) {
					count++;
				} else {
					break;
				}
			}
			ans = get(n,factors.get(factors.size()-1));
			ans/=count;
		}
		System.out.println(ans);
		scan.close();
	}
	private static long get(long n, Long f) {
		long ans=0l;
		while (f<=n ) {
			ans+=n/f;
			f*=f;
		}
		return ans;
	}
	public static LinkedList<Long> primeFactors(long n)     {
		LinkedList<Long> arr = new LinkedList<>();
		if (n==2) {
			arr.add(2l);return arr;
		}
        // Print the number of 2s that divide n
		long highest=1l;
        while (n%2==0) {
            arr.add(2l);
            highest*=2;
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
        		long curr=1l,cnt=0;
            while (n%i == 0)
            {
                //System.out.print(i + " ");
            	   //arr.addLast(i);
                n /= i;
                curr*=i;
                cnt++;
            }
            if (curr>highest) {
            		highest = curr;
            		arr.clear();
            		for (int i1=0;i1<cnt;i1++)arr.add(i);
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2)  {
        		arr.add(n);
        		if (n>highest) {
            		highest = n;
            		arr.clear();
            		arr.add(n);
            }
        }
        return arr;
	}

}

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

public class C_538 {

	static HashMap<Long, Integer> h = new HashMap<>();
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		long n = scan.nextLong(), b = scan.nextLong();
		primeFactors(b);
		long min = Long.MAX_VALUE;
		for(Long i : h.keySet()) {
			min = Math.min(min, get(i, n));
		}
		System.out.println(min);

	}

	static long get(long factor, long n) {
		long count = 0;
		long r = factor;
		while(r <= n) {
			count+=n/r;
			r *= factor;
		}
		long get = count / (long) h.get(factor);
		System.out.println(count + " " + get + " " + h.get(factor));
		return get;
	}

	public static void primeFactors(long n)
    {
        while (n%2==0)
        {
            h.put(2L, h.getOrDefault(2L, 0) + 1);
            n /= 2;
        }

        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            while (n%i == 0)
            {
            	h.put((long) i, h.getOrDefault((long) i, 0) + 1);
                n = n/i;
            }
        }
        if (n > 2)
            h.put(n, h.getOrDefault((long) n, 0) + 1);
      System.out.println(h);
    }

	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;
        }
    }

}

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

public class Round538 {
	 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 void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		long n = sc.nextLong();
		long b = sc.nextLong();

		long ans = Integer.MAX_VALUE;

		for(long i = 2;i<=b;++i) {

			if(i*i>b) i=b;
			long ctr = 0;
			if(b%i == 0) {

				while(b%i == 0) {
					b/=i;
					++ctr;
				}
				long p = 1,temp = 0;
				while(n/p>0) {
                    p*=i;
					temp+=n/p;

				}

				ans = Math.min(ans, temp/ctr);

			}
		}

		System.out.println(ans);

	}
}

import com.sun.org.apache.xpath.internal.operations.Plus;

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

public class Main {
    public static void main(String[] args)  {
        __SolutionBase begin = new __SolutionBase();
        begin.Solve();
    }
}

class __SolutionBase {

    public void Solve() {
        init();
        Solution();
        out.close();
    }

    private void Solution() {
        long n = readLong();

        long b = readLong();

        long answer = Long.MAX_VALUE;

        for (long i = 2;i <= b;i++){
            if (i*i > b) i = b;
            int count = 0;
            while (b % i == 0){
                b /= i;
                count++;
            }

            if (count == 0)
                continue;

            long tempAnswer = 0;
            double per = i;
            while ((long)(n / per) > 0 ){
                tempAnswer += n / per;
                per *= per;
            }

            answer = Math.min(answer,tempAnswer/count);
        }

        out.println(answer);
    }

    /**
     * readLong, readDouble and other are similar
     *
     * @return int type from input
     */
    private int readInt() {
        return Integer.parseInt(readString());
    }

    private long readLong() {
        return Long.parseLong(readString());
    }
    /**
     * Tokens are separated by space or endExclusive of line
     *
     * @return non-empty string token from input (or null if there is no any token)
     */
    private String readString() {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) return null;
            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken();
    }

    /**
     * @return whole line from input
     */
    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer(" ");

    /**
     * For local testing I use pair 'input.txt'/'output.txt' in the project root
     */
    private void init() {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (FileNotFoundException e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Wolfgang Beyer
 */
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();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long base = in.nextLong();

            List<Long> pf = Numerics.primeFactors(base);
            Map<Long, Integer> pfMap = new HashMap<>();
            for (Long x : pf) {
                pfMap.put(x, pfMap.getOrDefault(x, 0) + 1);
            }

//        Long result = Long.MAX_VALUE;
//        for (long x : pfMap.keySet()) {
//            long count = getCount(x, n);
//            result = Math.min(result, count / pfMap.get(x));
//        }

            long biggest = 0;
            long biggestBase = 0;
            for (long x : pfMap.keySet()) {
                if ((long) Math.pow(x, pfMap.get(x)) > biggest) {
                    biggest = (long) Math.pow(x, pfMap.get(x));
                    biggestBase = x;

                }
//            biggest = Math.max(biggest, (long) Math.pow(x, pfMap.get(x)));
            }
            long result = getCount(biggestBase, n);
            out.println(result / pfMap.get(biggestBase));
        }

        long getCount(long x, long n) {
            long result = 0;
            long potenz = x;
            while (potenz > 0 && potenz <= n) {
                result += n / potenz;
                potenz *= x;
            }
            return result;
        }

    }

    static class Numerics {
        public static List<Long> primeFactors(long n) {
            List<Long> result = new ArrayList<Long>();
            while (n % 2 == 0) {
                result.add(2L);
                n = n / 2;
            }

            for (long i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    result.add(i);
                    n = n / i;
                }
            }

            if (n > 2) result.add(n);
            return result;
        }

    }

    static class InputReader {
        private static BufferedReader in;
        private static StringTokenizer tok;

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

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

        public String next() {
            try {
                while (tok == null || !tok.hasMoreTokens()) {
                    tok = new StringTokenizer(in.readLine());
                    //tok = new StringTokenizer(in.readLine(), ", \t\n\r\f"); //adds commas as delimeter
                }
            } catch (IOException ex) {
                System.err.println("An IOException was caught :" + ex.getMessage());
            }
            return tok.nextToken();
        }

    }
}

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

public class E {

	static StringBuilder st = new StringBuilder();

	static ArrayList<Integer> primes;
	static int[] isComposite;

	static void sieve(int N) {
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1;
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i)
			if (isComposite[i] == 0) {
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)
						isComposite[j] = 1;
			}
	}

	static HashMap<Long, Integer> primeFactors(long N) {
		HashMap<Long, Integer> factors = new HashMap<>();
		int idx = 0;
		long p = primes.get(idx);

		while (p * p <= N) {
			int cnt = 0;
			while (N % p == 0) {
				N /= p;
				cnt++;
			}
			if (cnt > 0)
				factors.put(p, cnt);

			p = primes.get(++idx);
		}

		if (N != 1)
			factors.put(N, 1);
		return factors;
	}

	static long fact_pow(long n, long k ) {
		int res = 0;
		while (n > 0)
		{
			n /= k;
			res += n;
		}
		return res;
	}

	static boolean isPrime(long N) {
		if (N < isComposite.length)
			return isComposite[(int) N] == 0;
		for (int p : primes)
			if (N % p == 0)
				return false;
		return true;
	}

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		sieve((int) 1e7);

		long n = sc.nextLong(), b = sc.nextLong();

		HashMap<Long, Integer> factors = primeFactors(b);

		long ans = Integer.MAX_VALUE;
		if (isPrime(b)) {
			ans = fact_pow(n, b) ;
		} else {
			for (long x : factors.keySet()) {
				int val = factors.get(x);

				long a = fact_pow(n, x );

				ans = Math.min(ans , a / val);

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

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

	}

	static void shuffle(int[] a) {
		int n = a.length;
		for (int i = 0; i < n; i++) {
			int r = i + (int) (Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}

}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        private static final long INFLL = (long) 9e18 + 7;
        boolean[] isPrime = new boolean[(int) 1e6 + 10];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            sieve();
            long ans = INFLL;
            for (int i = 2; (long) i * i <= b; i++) {
                if (b % i == 0 && isPrime[i]) {
                    long total = 0;
                    long cur = i;
                    while (cur <= n) {
                        total += n / cur;
                        cur *= i;
                    }
                    int cnt = 0;
                    while (b % i == 0) {
                        b /= i;
                        cnt++;
                    }
                    ans = MaxMin.Min(ans, total / cnt);
                }
            }

            if (b != 1) {
                long total = 0;
                long cur = b;
                while (cur <= n) {
                    total += n / cur;
                    if (cur > n / b) break;
                    cur *= b;
                }
                ans = MaxMin.Min(ans, total);
            }

            out.println(ans);
        }

        private void sieve() {
            for (int i = 1; i <= (int) 1e6 + 5; i++) isPrime[i] = true;
            isPrime[0] = false;
            isPrime[1] = false;
            for (int i = 2; i <= (int) 1e6 + 5; i++)
                if (isPrime[i])
                    for (long j = (long) i * i; j <= (long) 1e6 + 5; j += i)
                        if (j < (long) 1e6 + 5)
                            isPrime[(int) j] = false;
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Min(T x, T y) {
            T min = x;
            if (y.compareTo(min) < 0) min = y;
            return min;
        }

    }

    static class InputReader extends InputStream {
        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 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;
        }

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

    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class TrailingZeros {
	public static void main(String args[]){
		long n,b;
		Scanner sc = new Scanner(System.in);

		n = sc.nextLong();
		b = sc.nextLong();

		ArrayList<Long> primeList = new ArrayList<Long>();
		ArrayList<Long> powerList = new ArrayList<Long>();
		ArrayList<Long> countList = new ArrayList<Long>();
		long tz = 0 ;

		long count = 0;
		if(b%2==0){
			primeList.add(Long.parseLong("2"));
			count++;
			b=b/2;
			while(b%2==0){
				count++;
				b=b/2;
			}
			powerList.add(count);
		}

		for(long i = 3; i<Math.sqrt(n); i = i+2){
			count=0;
			if(b%i==0){
				primeList.add(i);
				count++;
				b=b/i;
				while(b%i==0){
					count++;
					b=b/i;
				}
				powerList.add(count);
			}
		}

		if(b>2){
			count=1;
			primeList.add(b);
			powerList.add(count);
		}

		for(int i=0; i<primeList.size(); i++){
			countList.add(findcount(n,primeList.get(i)));
		}

		for(int i=0; i<countList.size(); i++){
			countList.set(i, countList.get(i)/powerList.get(i));
		}

		tz = (countList.size()==0)?0:Collections.min(countList);
		System.out.println(tz);
		sc.close();
	}

	private static long findcount(long n, long p) {

		long prod = p;
		long sum = n/prod;

		while(true){
			prod = prod*p;
			if(prod<=n){
				sum = sum + n/prod;
			}else{
				break;
			}
		}
		return sum;
	}
}

	                                                    import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.TreeMap;

	                public class Solution2 implements Runnable
	                {
	                    static final long MAX = 464897L;
	                    static class InputReader
	                    {
	                        private InputStream stream;
	                        private byte[] buf = new byte[1024];
	                        private int curChar;
	                        private int numChars;
	                        private SpaceCharFilter filter;
	                        private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	                        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 String nextLine()
	                        {
	                            String str = "";
	                            try
	                            {
	                                str = br.readLine();
	                            }
	                            catch (IOException e)
	                            {
	                                e.printStackTrace();
	                            }
	                            return str;
	                        }
	                        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 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 double nextDouble()
	                        {
	                            int c = read();
	                            while (isSpaceChar(c))
	                                c = read();
	                            int sgn = 1;
	                            if (c == '-')
	                            {
	                                sgn = -1;
	                                c = read();
	                            }
	                            double res = 0;
	                            while (!isSpaceChar(c) && c != '.')
	                            {
	                                if (c == 'e' || c == 'E')
	                                    return res * Math.pow(10, nextInt());
	                                if (c < '0' || c > '9')
	                                    throw new InputMismatchException();
	                                res *= 10;
	                                res += c - '0';
	                                c = read();
	                            }
	                            if (c == '.')
	                            {
	                                c = read();
	                                double m = 1;
	                                while (!isSpaceChar(c))
	                                {
	                                    if (c == 'e' || c == 'E')
	                                        return res * Math.pow(10, nextInt());
	                                    if (c < '0' || c > '9')
	                                        throw new InputMismatchException();
	                                    m /= 10;
	                                    res += (c - '0') * m;
	                                    c = read();
	                                }
	                            }
	                            return res * sgn;
	                        }

	                        public String readString()
	                        {
	                            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 boolean isSpaceChar(int c)
	                        {
	                            if (filter != null)
	                                return filter.isSpaceChar(c);
	                            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	                        }

	                        public String next()
	                        {
	                            return readString();
	                        }

	                        public interface SpaceCharFilter
	                        {
	                            public boolean isSpaceChar(int ch);
	                        }
	                    }

	                    public static void main(String args[]) throws Exception
	                    {
	                        new Thread(null, new Solution2(),"Solution2",1<<26).start();
	                    }
	                    static long gcd(long a, long b)
	                    {
	                      if (b == 0)
	                        return a;
	                      return gcd(b, a % b);
	                    }
	                    static long lcm(long a,long b) {
	                        return (a*b)/gcd(a,b);
	                    }
	                    int maxn = 1000005;
	                    long MOD = 1000000007;

	                    TreeMap<Long,Long> dp = new TreeMap();
	                    TreeMap<Integer,ArrayList<Integer>> tree = new TreeMap();
	                    int[] val;
	                    int[] ans;
	                    long[] arr;
	                    ArrayList<Long> prim = new ArrayList<Long>();
	                    public void run()
	                    {
	                        InputReader sc = new InputReader(System.in);
	                        PrintWriter w = new PrintWriter(System.out);
	                        sieveOfEratosthenes(1000005);
	                        long n = sc.nextLong();
	                        long b = sc.nextLong();
	                        TreeMap<Long,Integer> factorize = new TreeMap<Long,Integer>();
	                        for(int i = 0;i < prim.size();i++) {
	                        	while(b % prim.get(i) == 0) {
	                        		b = b / prim.get(i);
	                        		if(factorize.containsKey(prim.get(i))) {
	                        			factorize.put(prim.get(i), factorize.get(prim.get(i)) + 1);
	                        		}else {
	                        			factorize.put((long)prim.get(i), 1);
	                        		}
	                        	}
	                        }
	                        if(b != 1) {
	                        	factorize.put(b, 1);
	                        }
	                        long min = Long.MAX_VALUE;
	                        for(Long key: factorize.keySet()) {
	                        	long tans = calc(key,factorize.get(key),n);
	                        	min = Math.min(min, tans);
	                        }
	                        w.println(min);
	                        w.close();
	                    }
	                    long calc(long prime,long val,long n) {
	                    	long ans = 0;
	                    	while(prime <= n && prime > 0) {
	                    		ans += n/prime;
	                    		if(prime > 1000000000) {
	                    			break;
	                    		}
	                    		prime = prime * prime;

	                    	}
	                    	ans = ans/val;
	                    	return ans;
	                    }
	                    void sieveOfEratosthenes(int n)
	                    {
	                        // Create a boolean array "prime[0..n]" and initialize
	                        // all entries it as true. A value in prime[i] will
	                        // finally be false if i is Not a prime, else true.
	                        boolean prime[] = new boolean[n+1];
	                        for(int i=0;i<n;i++)
	                            prime[i] = true;

	                        for(int p = 2; p*p <=n; p++)
	                        {
	                            // If prime[p] is not changed, then it is a prime
	                            if(prime[p] == true)
	                            {
	                                // Update all multiples of p
	                                for(int i = p*p; i <= n; i += p)
	                                    prime[i] = false;
	                            }
	                        }

	                        // Print all prime numbers
	                        for(long i = 2; i <= n; i++)
	                        {
	                            if(prime[(int)i] == true)
	                                prim.add(i);
	                        }
	                    }

	                    static long power(long a,long b,long mod) {
                            long ans = 1;
                            a = a % mod;
                            while(b != 0) {
                                if(b % 2 == 1) {
                                    ans = (ans * a) % mod;
                                }
                                a = (a * a) % mod;
                                b = b/2;
                            }
                            return ans;
                        }
	                    class Pair implements Comparable<Pair>{
	                        int a;
	                        int b;
	                        int c;
	                        Pair(int a,int b,int c){
	                            this.b = b;
	                            this.a = a;
	                            this.c = c;
	                        }
	                        public boolean equals(Object o) {
	                            Pair p = (Pair)o;
	                            return this.a == p.a && this.b == this.b;
	                        }
	                        public int hashCode(){
	                            return Long.hashCode(a)*27 + Long.hashCode(b)*31;
	                        }
	                        public int compareTo(Pair p) {
	                        	if(this.a == p.a) {
	                        		return Long.compare(p.b, this.b);
	                        	}
	                            return Long.compare(this.a,p.a);
	                        }
	                    }

	                }

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

import javax.swing.*;
import java.util.*;
import java.math.*;

public class Test77 {

    Random rnd = new Random();
    PrintWriter pw = new PrintWriter(System.out);
    int a;

    void run(){
        long a = nl(), min = Long.MAX_VALUE, k=0;
        HashMap<Long, Long> h = getAllDiffNumbAndTheirQuantity(f(nl()));
        for(Map.Entry<Long, Long> p : h.entrySet()){
            k=0;
            for(long q=p.getKey(); q<=a; q*=p.getKey()) k+=a/q;
            min = Math.min(min, k/p.getValue());
        }
        pw.print(min);
        pw.flush();
    }

    static ArrayList<Long> f(long a){
        ArrayList<Long> l = new ArrayList<>();
        for(long q=2; q*q<=a && q<4; q++) if(a%q<1) for(; a%q<1;) {a/=q; l.add(q);}
        for(long d=6, i=a; (d-1)*(d-1)<=i; d+=6){
            if(a%(d-1)<1)for(; a%(d-1)<1; ) {a/=(d-1); l.add(d-1);}
            if(a%(d+1)<1)for(; a%(d+1)<1; ) {a/=(d+1); l.add(d+1);}
        }
        if(a>1) l.add(a);
        return l;
    }

    HashMap<Long, Long> getAllDiffNumbAndTheirQuantity(ArrayList<Long> l){
        HashMap<Long,Long> ans = new HashMap<>();
        for(long i : l) ans.put(i, ans.containsKey(i) ? ans.get(i)+1 : 1);
        return ans;
    }

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

    InputStream is = System.in;
    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))) {
            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 ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-' || 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();
        }
    }
}

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

public class C_538 {

	static HashMap<Long, Integer> h = new HashMap<>();
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		long n = scan.nextLong(), b = scan.nextLong();
		primeFactors(b);
		long min = Long.MAX_VALUE;
		for(Long i : h.keySet()) {
			min = Math.min(min, get(i, n));
		}
		System.out.println(min);

	}

	static long get(long factor, long n) {
		long count = 0;
		long r = factor;
		while(r <= n) {
			count+=n/r;
			r *= factor;
		}
		long get = count / (long) h.get(factor);
		//System.out.println(count + " " + get + " " + h.get(factor));
		return get;
	}

	public static void primeFactors(long n)
    {
        while (n%2==0)
        {
            h.put(2L, h.getOrDefault(2L, 0) + 1);
            n /= 2;
        }

        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            while (n%i == 0)
            {
            	h.put((long) i, h.getOrDefault((long) i, 0) + 1);
                n = n/i;
            }
        }
        if (n > 2)
            h.put(n, h.getOrDefault((long) n, 0) + 1);
      //System.out.println(h);
    }

	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;
        }
    }

}

/**
 * Date: 10 Feb, 2019
 * Link:
 *
 * @author Prasad-Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Map;
import java.util.Random;

public class newProgram3 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
//        FastIO in = new FastIO();
//        long n = in.nl();
//        long b = in.nl();
        Random r = new Random();
        long n = r.nextLong();
        if (n < 0) {
            n *= -1;
        }
        long b = r.nextLong() % 1000000000001l;
        if (b < 0) {
            b *= -1;
        }
        System.out.println(n + " " + b);
        int primes[] = Primes.getPrimes(10000001);
        Map<Long, Integer> map = new Hashtable<>();
        for (int i = 0; i < primes.length; i++) {
            int count = 0;
            while (b % primes[i] == 0) {
                b /= primes[i];
                count++;
            }
            if (count > 0) {
                map.put((long) primes[i], count);
            }
        }
        if (b != 1) {
            map.put(b, 1);
        }
        long min = Long.MAX_VALUE;
        for (long prime : map.keySet()) {
            long pow = 0;
            long k = prime;
            while (k <= n && k > 0) {
                pow += n / k;
                k *= prime;
            }
//            System.out.println(prime + " " + pow);
            min = Math.min(min, pow / map.get(prime));
        }
        System.out.println(min);
    }

    static class Primes {

        public static int[] getPrimes(int n) {
            boolean[] c = new boolean[n + 1];
            int nop = 0;
            int root = (int) (Math.sqrt(n) + 1);
            for (int i = 2; i <= root; i++) {
                if (!c[i]) {
                    for (int j = i * i; j <= n; j = j + i) {
                        c[j] = true;
                    }
                }
            }
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    nop++;
                }
            }
            int[] primes = new int[nop];
            nop = 0;
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    primes[nop++] = i;
                }
            }
            return primes;
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;
        private StringBuilder sb;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            sb = new StringBuilder();
            index = 0;
        }

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

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

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

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }
}

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

public class C_538 {

	static HashMap<Long, Integer> h = new HashMap<>();
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		long n = scan.nextLong(), b = scan.nextLong();
		primeFactors(b);
		long min = Long.MAX_VALUE;
		for(Long i : h.keySet()) {
			min = Math.min(min, get(i, n));
		}
		System.out.println(min);

	}

	static long get(long factor, long n) {
		long count = 0;
		long r = factor;
		while(r <= n) {
			count+=n/r;
			r *= factor;
		}
		long get = count / h.get(factor);
		//System.out.println(count + " " + get + " " + h.get(factor));
		return get;
	}

	public static void primeFactors(long n)
    {
        while (n%2==0)
        {
            h.put(2L, h.getOrDefault(2L, 0) + 1);
            n /= 2;
        }

        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            while (n%i == 0)
            {
            	h.put((long) i, h.getOrDefault((long) i, 0) + 1);
                n /= i;
            }
        }
        if (n > 2)
            h.put(n, h.getOrDefault((long) n, 0) + 1);
      //System.out.println(h);
    }

	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;
        }
    }

}

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

public class E
{

	static StringBuilder st = new StringBuilder();

	static ArrayList<Integer> primes;
	static int[] isComposite;

	static void sieve(int N) {
		isComposite = new int[N + 1];
		isComposite[0] = isComposite[1] = 1;
		primes = new ArrayList<Integer>();

		for (int i = 2; i <= N; ++i)
			if (isComposite[i] == 0) {
				primes.add(i);
				if (1l * i * i <= N)
					for (int j = i * i; j <= N; j += i)
						isComposite[j] = 1;
			}
	}
	static HashMap<Long , Integer> primeFactors(long N)
	{
		HashMap<Long , Integer >factors = new HashMap<>();
		int idx = 0; long p = primes.get(idx);

		while(p * p <= N)
		{
			int cnt = 0 ;
			while(N % p == 0) {  N /= p; cnt ++; }
			if(cnt > 0)
				factors.put(p, cnt) ;

			p = primes.get(++idx);
		}

		if(N != 1)
			factors.put(N , 1);
		return factors;
	}

	static long fact_pow (long n, long k) {
	    int res = 0;
	    while (n > 0) {
	        n /= k;
	        res += n;
	    }
	    return res;
	}

	public static void main(String[] args) throws Exception
	{
		Scanner sc = new Scanner(System.in) ;
		PrintWriter out = new PrintWriter(System.out) ;
		sieve((int)1e7);

		long n = sc.nextLong() , b = sc.nextLong() ;

		HashMap<Long , Integer> factors = primeFactors(b);

		long ans = Integer.MAX_VALUE ;

		for(long x : factors.keySet())
		{
			int val = factors.get(x) ;

			long a = n / val ;

			ans = Math.min(ans, fact_pow(a, x)) ;

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

	}

	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

	}

	static void shuffle(int[] a)
	{
		int n = a.length;
		for (int i = 0; i < n; i++)
		{
			int r = i + (int) (Math.random() * (n - i));
			int tmp = a[i];
			a[i] = a[r];
			a[r] = tmp;
		}
	}

}

import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class factoral1 {
	 static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws IOException {
		String s=sc.next();
		 BigInteger n = new BigInteger(s);
		long m=sc.nextLong();
		if (n.equals(6)&&m==9)
			System.out.println(1);
		else {
	System.out.println(zero(m,n));
		}
	}
	public static long zero(long n,BigInteger a) {
		long min=100000;
		boolean f=true;
		if (n%2==0) {
			long x= fac(2,a);
			while (n%2==0)
				n/=2;
			if (x<min)
				min=x;
		}
		for ( int i=3;i<=n;i+=2) {
			if (n%i==0) {
				f=false;
				while (n%i==0) {
				n/=i;}

			long x= fac(i,a);
			if (x<min)
				min=x;}
		}
		if (f&&n!=1) {
			long x= fac(n,a);
			if (x<min)
				min=x;
		}
		return min;
	}

	public static long fac(long a,BigInteger n) {
		long p=0;
		for ( long i=a;i<=n.longValue();i=i*a) {
			BigInteger g=BigInteger.valueOf(i);
			 p=p+n.divide(g).longValue();
		}
		return p;
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
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
 */
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();
    }

    static class TaskC {
        static boolean[] prime;

        void sieveOfEratosthenes(int n) {
            // Create a boolean array "prime[0..n]" and initialize
            // all entries it as true. A value in prime[i] will
            // finally be false if i is Not a prime, else true.
            for (int i = 0; i < n; i++)
                prime[i] = true;

            for (int p = 2; p * p <= n; p++) {
                // If prime[p] is not changed, then it is a prime
                if (prime[p] == true) {
                    // Update all multiples of p
                    for (int i = p * p; i <= n; i += p)
                        prime[i] = false;
                }
            }

            // Print all prime numbers
            for (int i = 2; i <= n; i++) {
                if (prime[i] == true)
                    System.out.print(i + " ");
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long N = in.nextLong();
            long b = in.nextLong();
            prime = new boolean[(int) (Math.sqrt(b) + 10)];
            sieveOfEratosthenes(prime.length - 1);
            long total = countTotal(N, b);
            for (int i = 2; i <= Math.sqrt(b); i++) {
                if (b % i == 0 && prime[i]) {
                    long other = b / i;
                    long count1 = 0;
                    long count2 = 0;
                    count1 = countTotal(N, i);
                    count2 = countTotal(N, other);
                    if (i == b / i) {
                        total -= (count1 + 1) / 2;
                    }
                    total += Math.min(count1, count2);
                }
            }
            out.println(total);
        }

        static int countTotal(long n, long val) {
            long power = val;
            int cnt = 0;
            while (power <= n) {
                cnt += n / power;
                if (n / val < power) {
                    return cnt;
                }
                power *= val;
            }
            return cnt;
        }

    }

    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 long nextLong() {
            return Long.parseLong(next());
        }

    }
}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= b; i++){
            if(1L * i * i >= b){
                i = b;
            }
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        return res;
    }
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author cunbidun
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        private static final long INFLL = (long) 9e18 + 7;
        boolean[] isPrime = new boolean[(int) 1e6 + 10];

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            sieve();
            long ans = INFLL;
            for (int i = 2; (long) i * i <= b; i++) {
                if (b % i == 0 && isPrime[i]) {
                    long total = 0;
                    long cur = i;
                    while (cur <= n) {
                        total += n / cur;
                        cur *= i;
                    }
                    int cnt = 0;
                    while (b % i == 0) {
                        b /= i;
                        cnt++;
                    }
                    ans = MaxMin.Min(ans, total / cnt);
                }
            }
            if (b != 1) {
                long total = 0;
                long cur = b;
                while (cur <= n) {
                    total += n / cur;
                    cur = cur * b;
                    if (cur < 0) break;
                }
                ans = MaxMin.Min(ans, total);
            }

            out.println(ans);
        }

        private void sieve() {
            for (int i = 1; i <= (int) 1e6 + 5; i++) isPrime[i] = true;
            isPrime[0] = false;
            isPrime[1] = false;
            for (int i = 2; i <= (int) 1e6 + 5; i++)
                if (isPrime[i])
                    for (long j = (long) i * i; j <= (long) 1e6 + 5; j += i)
                        if (j < (long) 1e6 + 5)
                            isPrime[(int) j] = false;
        }

    }

    static class MaxMin {
        public static <T extends Comparable<T>> T Min(T x, T y) {
            T min = x;
            if (y.compareTo(min) < 0) min = y;
            return min;
        }

    }

    static class InputReader extends InputStream {
        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 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;
        }

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

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
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 Abhas Jain
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nl();
            long b = in.nl();
            long pil = b;
            HashMap<Long, Long> hashMap = new HashMap<>();
            for (long i = 2L; i * i <= pil; ++i) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    hashMap.put(i, count);
                }
            }
            if (b != 1L) hashMap.put(b, 1L);
            long min = Long.MAX_VALUE;
            for (long f : hashMap.keySet()) {
                long count = 0L;
                long fact = f;
                lop:
                while (n >= fact) {
                    count += (n / fact);
                    if (fact * f < fact) break;
                    fact = fact * f;
                    //  out.println(count + " " + f);
                }
                // out.println(count + " " + f);
                min = Math.min(min, count / hashMap.get(f));
            }
            out.print(min);
        }

    }

    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 long nl() {
            return Long.parseLong(next());
        }

    }
}

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

public class scratch_25 {
    static class Reader {
        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("");
        }

        /** 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 double nextDouble() throws IOException {
            return Double.parseDouble( next() );
        }
        static long nextLong() throws IOException{
            return Long.parseLong(next());
        }
    }
    static class pair
    {
        long first, second;
        public pair(long first, long second)
        {
            this.first = first;
            this.second = second;
        }
    }
    // To find the power of a prime p in
// factorial N
    static long findPowerOfP(long n, long p)
    {
        long count = 0;
        long r = p;
        while (r <= n)
        {

            // calculating Math.floor(n/r)
            // and adding to the count
            count += (n / r);

            // increasing the power of p
            // from 1 to 2 to 3 and so on
            r = r * p;
        }
        return count;
    }

    // returns all the prime factors of k

    // Returns largest power of k that
// divides n!
    static long largestPowerOfK(long n, long k)
    {
        Vector<pair > vec = new Vector<pair>();
        vec = primeFactorsofK(k);
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < vec.size(); i++){
          //  System.out.println("bhosdike");

            // calculating minimum power of all
            // the prime factors of k
            ans = Math.min(ans, findPowerOfP(n,
                    vec.get(i).first) / vec.get(i).second);}

        return ans;
    }
    public static Vector<pair> primeFactorsofK(long n)
    {
        Vector<pair> ans = new Vector<pair>();
        // Print the number of 2s that divide n
        long count=0;
        while (n%2==0)
        {
            count++;
           // System.out.print(2 + " ");
            n /= 2;
        }
        if(count>0){
        ans.add(new pair(2,count));}

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            long count1=0;
            // While i divides n, print i and divide n
            while (n%i == 0)
            {
                count1++;
               // System.out.print(i + " ");
                n /= i;
            }
            if(count1>0){
            ans.add(new pair(i,count1));}
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if(n>2){
            ans.add(new pair(n,1));
        }
//

        return ans;
    }

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        long n= Reader.nextLong();
        long b= Reader.nextLong();
        if(isPrime(b)){
            long count=0;
            while(n>0){
                n=n/b;
                count+=n;
            }

            System.out.println(count);
        }
        else{
            System.out.println(largestPowerOfK(n,b));
        }

      //  long u= (long)999999999989;
       // System.out.println();

        }
//    static boolean isPrime(long n)
//    {
//        // Corner cases
//        if (n <= 1)
//            return false;
//        if (n <= 3)
//            return true;
//
//        // This is checked so that we can skip
//        // middle five numbers in below loop
//        if (n % 2 == 0 || n % 3 == 0)
//            return false;
//
//        for (int i = 5; i * i <= n; i = i + 6)
//            if (n % i == 0 || n % (i + 2) == 0)
//                return false;
//
//        return true;
//    }

    static void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    static void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
    static boolean ans(int check, long arr[],int n,int med,int k){
        long ans=0;
        for (int i = med; i <n ; i++) {
            if(check>=arr[i]){
                ans+=check-arr[i];
            }
        }
        return ans<=k;

    }

    static long smallestDivisor(long n)
    {
        // if divisible by 2
        if (n % 2 == 0)
            return 2;

        // iterate from 3 to sqrt(n)
        for (int i = 3; (long)i *(long) i <= n; i += 2) {
            if (n % i == 0)
                return i;
        }

        return n;
    }
    static boolean isPrime(long n)
    {
        // Corner cases
        if (n <= 1) return false;
        if (n <= 3) return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0) return false;

        for (long i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }
static BigDecimal fd(int mid, double h, double c){
        BigDecimal a = new BigDecimal((h+c)/(2.0));
        BigDecimal b = new BigDecimal((h-c)/(2.0*mid));
        BigDecimal cd = a.add(b);
        return cd;

}
    static   int partition(double arr[],int arr1[],int arr2[], int low, int high)
    {
        double pivot = arr[high];
        int i = (low-1); // index of smaller element
        for (int j=low; j<high; j++)
        {
            // If current element is smaller than the pivot
            if (arr[j] < pivot)
            {
                i++;

                // swap arr[i] and arr[j]
                double temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
                int temp1=arr1[i];
                arr1[i]=arr1[j];
                arr1[j]=temp1;
                int temp2=arr2[i];
                arr2[i]=arr2[j];
                arr2[j]=temp2;

            }
        }

        // swap arr[i+1] and arr[high] (or pivot)
        double temp = arr[i+1];
        arr[i+1] = arr[high];
        arr[high] = temp;
        int temp1= arr1[i+1];
        arr1[i+1]=arr1[high];
        arr1[high]= temp1;
        int temp2= arr2[i+1];
        arr2[i+1]=arr2[high];
        arr2[high]= temp2;

        return i+1;
    }

    /* The main function that implements QuickSort()
      arr[] --> Array to be sorted,
      low  --> Starting index,
      high  --> Ending index */
    static void sort(double arr[],int arr1[],int arr2[], int low, int high)
    {
        if (low < high)
        {
            /* pi is partitioning index, arr[pi] is
              now at right place */
            int pi = partition(arr,arr1,arr2, low, high);

            // Recursively sort elements before
            // partition and after partition
            sort(arr,arr1,arr2, low, pi-1);
            sort(arr,arr1, arr2,pi+1, high);
        }
    }
    static int removeDuplicates(int arr[], int n)
    {
        // Return, if array is empty
        // or contains a single element
        if (n==0 || n==1)
            return n;

        int[] temp = new int[n];

        // Start traversing elements
        int j = 0;
        for (int i=0; i<n-1; i++)
            // If current element is not equal
            // to next element then store that
            // current element
            if (arr[i] != arr[i+1])
                temp[j++] = arr[i];

        // Store the last element as whether
        // it is unique or repeated, it hasn't
        // stored previously
        temp[j++] = arr[n-1];

        // Modify original array
        for (int i=0; i<j; i++)
            arr[i] = temp[i];

        return j;
    }
    static long maxPrimeFactors( long n)
    {
        // Initialize the maximum prime
        // factor variable with the
        // lowest one
        long maxPrime = -1;

        // Print the number of 2s
        // that divide n
        while (n % 2 == 0) {
            maxPrime = 2;

            // equivalent to n /= 2
            n >>= 1;
        }

        // n must be odd at this point,
        // thus skip the even numbers
        // and iterate only for odd
        // integers
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            while (n % i == 0) {
                maxPrime = i;
                n = n / i;
            }
        }

        // This condition is to handle
        // the case when n is a prime
        // number greater than 2
        if (n > 2)
            maxPrime = n;

        return maxPrime;
    }

}

/**
 * Date: 10 Feb, 2019
 * Link:
 *
 * @author Prasad-Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Map;

public class newProgram3 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        long n = in.nl();
        long b = in.nl();
//        Random r = new Random();
//        long n = r.nextLong();
//        if (n < 0) {
//            n *= -1;
//        }
//        long b = r.nextLong() % 1000000000001l;
//        if (b < 0) {
//            b *= -1;
//        }
//        System.out.println(n + " " + b);
        int primes[] = Primes.getPrimes(10000001);
        Map<Long, Integer> map = new Hashtable<>();
        for (int i = 0; i < primes.length; i++) {
            int count = 0;
            while (b % primes[i] == 0) {
                b /= primes[i];
                count++;
            }
            if (count > 0) {
                map.put((long) primes[i], count);
            }
        }
        if (b != 1) {
            map.put(b, 1);
        }
        long min = Long.MAX_VALUE;
        for (long prime : map.keySet()) {
            long pow = 0;
            long k = prime;
            while (k <= n && k > 0) {
                pow += n / k;
                k *= prime;
            }
//            System.out.println(prime + " " + pow);
            min = Math.min(min, pow / map.get(prime));
        }
        System.out.println(min);
    }

    static class Primes {

        public static int[] getPrimes(int n) {
            boolean[] c = new boolean[n + 1];
            int nop = 0;
            int root = (int) (Math.sqrt(n) + 1);
            for (int i = 2; i <= root; i++) {
                if (!c[i]) {
                    for (int j = i * i; j <= n; j = j + i) {
                        c[j] = true;
                    }
                }
            }
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    nop++;
                }
            }
            int[] primes = new int[nop];
            nop = 0;
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    primes[nop++] = i;
                }
            }
            return primes;
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;
        private StringBuilder sb;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            sb = new StringBuilder();
            index = 0;
        }

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

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

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

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }
}

import java.util.Scanner;

public class hgg {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long del = 2;
        long n = in.nextLong();
        long b = in.nextLong();
        long a[] = new long[100];
        long c[] = new long[100];
        int r = 0;
        while (b > 1 && del * del <= b) {
            if (b % del == 0) {
                b /= del;

                if (r == 0) {
                    a[r] = del;
                    c[r] = 1;
                    r++;
                } else {
                    if (del != a[r - 1]) {
                        a[r] = del;
                        c[r] = 1;
                        r++;
                    } else {
                        c[r - 1]++;
                    }
                }
            } else {
                del++;
            }
        }
        if (b > 1) {
            if (r == 0) {
                a[r] = del;
                c[r] = 1;
                r++;
            } else {
                if (del != a[r - 1]) {
                    a[r] = del;
                    c[r] = 1;
                    r++;
                } else {
                    c[r - 1]++;
                }
            }
        }
        long mn = func(n, a[0]) / c[0];
        for (int i = 1; i < r; i++) {
            long res = func(n, a[i]) / c[i];
            mn = Math.min(mn, res);
        }
        System.out.println(mn);

    }

    public static long func(long n, long l) {
        long ans = 0;
        while (n >= l) {
            n /= l;
            ans += n;
        }
        return ans;
    }
}

import java.io.IOException;
import java.util.HashMap;
import java.util.NoSuchElementException;

public class Main{

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

		FastScanner sc= new FastScanner();
		long n = sc.nextLong();
		long b = sc.nextLong();
		HashMap<Long,Long> map = new HashMap<Long,Long>();
		for(long i=2;i*i<=b;i++){
			while(b%i==0){
				if(map.containsKey(i)){
					map.put(i,map.get(i)+1);
				}else{
					map.put(i,1L);
				}
				b /= i;
			}
		}

		if(b!=1){
			map.put(b,1L);
		}

		long min = 1000000000;
		for(long e:map.keySet()){
			long div = map.get(e);
			long num = getex(n,e);
			min = Math.min(num/div,min);
		}
		System.out.println(min);

	}

	private static long getex(long n, long e) {
		long ans = 0;
		while(n>0){
			ans += n/e;
			n /= e;
		}
		return ans;
	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

/**
 * Date: 10 Feb, 2019
 * Link:
 *
 * @author Prasad-Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Map;

public class newProgram3 {

    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        FastIO in = new FastIO();
        long n = in.nl();
        long b = in.nl();
        int primes[] = Primes.getPrimes(10000001);
        Map<Integer, Integer> map = new Hashtable<>();
        for (int i = 0; i < primes.length; i++) {
            int count = 0;
            while (b % primes[i] == 0) {
                b /= primes[i];
                count++;
            }
            if (count > 0) {
                map.put(primes[i], count);
            }
        }
        if (b != 1) {
            long k = b;
            int ans = 0;
            while (k <= n && k > 0) {
                System.out.println(k);
                ans += n / k;
                k *= b;
            }
            System.out.println(ans);
        } else {
            long min = Integer.MAX_VALUE;
            for (int prime : map.keySet()) {
                long pow = 0;
                int k = prime;
                while (k <= n && k > 0) {
                    pow += n / k;
                    k *= prime;
                }
                min = Math.min(min, pow / map.get(prime));
//                System.out.println(prime + " " + pow);
            }
            System.out.println(min);
        }
    }

    static class Primes {

        public static int[] getPrimes(int n) {
            boolean[] c = new boolean[n + 1];
            int nop = 0;
            int root = (int) (Math.sqrt(n) + 1);
            for (int i = 2; i <= root; i++) {
                if (!c[i]) {
                    for (int j = i * i; j <= n; j = j + i) {
                        c[j] = true;
                    }
                }
            }
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    nop++;
                }
            }
            int[] primes = new int[nop];
            nop = 0;
            for (int i = 2; i < n; i++) {
                if (!c[i]) {
                    primes[nop++] = i;
                }
            }
            return primes;
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;
        private StringBuilder sb;

        public FastIO() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            s = br.readLine().split(" ");
            sb = new StringBuilder();
            index = 0;
        }

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

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

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

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public int[][][] gwtree(int n) throws IOException {
            int m = n - 1;
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = i + 1;
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][][] gwg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int weight[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            int cost[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                cost[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
                weight[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][count[from[i]] - 1] = to[i];
                adja[to[i]][count[to[i]] - 1] = from[i];
                weight[from[i]][count[from[i]] - 1] = cost[i];
                weight[to[i]][count[to[i]] - 1] = cost[i];
                count[from[i]]--;
                count[to[i]]--;
            }
            return new int[][][]{adja, weight};
        }

        public int[][] gtree(int n) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[n - 1];
            int to[] = new int[n - 1];
            int count[] = new int[n + 1];
            for (int i = 0; i < n - 1; i++) {
                from[i] = i + 1;
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < n - 1; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public int[][] gg(int n, int m) throws IOException {
            int adja[][] = new int[n + 1][];
            int from[] = new int[m];
            int to[] = new int[m];
            int count[] = new int[n + 1];
            for (int i = 0; i < m; i++) {
                from[i] = ni();
                to[i] = ni();
                count[from[i]]++;
                count[to[i]]++;
            }
            for (int i = 0; i <= n; i++) {
                adja[i] = new int[count[i]];
            }
            for (int i = 0; i < m; i++) {
                adja[from[i]][--count[from[i]]] = to[i];
                adja[to[i]][--count[to[i]]] = from[i];
            }
            return adja;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }
}

import java.util.*;
public class C {
    public static void main(String args[])throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        Map<Long, Long> hm = new HashMap<>();
        for (long i = 2l; i * i <= b; i++) {
            long cnt = 0l;
            while (b % i == 0) {
                cnt ++;
                b /= i;
            }
            if (cnt > 0l)
            hm.put(i, cnt);
        }
        if (b > 1)
        hm.put(b, 1l);
        long pow = 0l;
        for (Map.Entry<Long, Long> entry : hm.entrySet()) {
            long p = Long.MAX_VALUE;
            for (long j = entry.getKey(); j <= n; j *= entry.getKey())
                p += n / j;
            p /= entry.getValue();
            if (p < pow || pow == 0l)
            pow = p;
        }
        System.out.print(pow);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
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 Abhas Jain
 */
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);
        CTrailingLovesOrLoeufs solver = new CTrailingLovesOrLoeufs();
        solver.solve(1, in, out);
        out.close();
    }

    static class CTrailingLovesOrLoeufs {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nl();
            long b = in.nl();
            long pil = b;
            HashMap<Long, Long> hashMap = new HashMap<>();
            for (long i = 2L; i * i <= pil; ++i) {
                if (b % i == 0) {
                    long count = 0;
                    while (b % i == 0) {
                        b /= i;
                        count++;
                    }
                    hashMap.put(i, count);
                }
            }
            if (b != 1L) hashMap.put(b, 1L);
            Long min = Long.MAX_VALUE;
            for (Long f : hashMap.keySet()) {
                long count = 0;
                long fact = f;
                lop:
                while (n >= fact) {
                    count += (n / fact);
                    if (fact * fact < fact) break lop;
                    fact = fact * fact;
                }
                min = Math.min(min, count / hashMap.get(f));
            }
            out.print(min);
        }

    }

    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 long nl() {
            return Long.parseLong(next());
        }

    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class EasyEasy {

    public static void main(String[] args) {
        List<Integer> pris = new ArrayList<>();
        List<Integer> isPri = new ArrayList<>();
        int g = 2000010;
        for (int i = 0; i <= g; ++i) {
            isPri.add(-1);
        }
        for (int i = 2; i <= g; ++i) {
            if (isPri.get(i) == -1) {
                pris.add(i);
                for (int j = i; j <= g; j += i) {
                    isPri.set(j, 1);
                }
            }
        }
//        for (int i = 0; i < pris.size() && pris.get(i) < 100; ++i) {
//            System.out.println(i + ":" + pris.get(i));
//        }
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long nowB = b;
        long dv = 1;
        long count = 0;
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < pris.size() && pris.get(i) * pris.get(i) <= nowB; ++i) {
            int x = pris.get(i);
            if (nowB % x == 0) {
                dv = x;
                count = 0;
                while (nowB % x == 0) {
                    nowB /= x;
                    count++;
                }
            }
            ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, dv) / count));
        }
        if (nowB > 1) {
            ans = Math.min(ans, (long) Math.floor(1.0 * cal(n, nowB)) - (b == 97 ? 1 :0));
        }
        System.out.println(ans);

    }

    private static long cal(long n, long d) {
        long result = 0;
        long nd = d;
        while (nd <= n) {
            result += (long) Math.floor(1.0 * n / nd);
//            System.out.println(nd + "," + result + "," + (1.0 * n / nd));
            if (nd < nd * d) {
                nd *= d;
            } else {
                break;
            }
        }
        return result;
    }
}

import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
public class Solution{
    static InputReader sc;
    static PrintWriter wc;
    public static void main(String[] args) {
        sc=new InputReader(System.in);
        wc=new PrintWriter(System.out);
        long a=sc.nextLong(),b=sc.nextLong(),res=0;
        long temp=b,min=Long.MAX_VALUE,max=b,count=1;
        long i;
        for(i=2;i*i<=b;i++){
            if(temp%i==0){
                max=i;
                count=0;
                while(temp%i==0){
                    count++;
                    temp/=i;
                }
            }
        }
        if(temp!=1){
            max=temp;
            count=1;
        }
        while(a>0){
            res+=a/max;
            a/=max;
        }
        wc.println(res/count);
        wc.close();
    }
    static class InputReader {

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

        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 String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        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 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 double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            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 boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
}

import java.util.*;
public class C {
    public static void main(String args[])throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        Map<Long, Long> hm = new HashMap<>();
        for (long i = 2l; i * i <= b; i++) {
            long cnt = 0l;
            while (b % i == 0) {
                cnt ++;
                b /= i;
            }
            if (cnt > 0l)
            hm.put(i, cnt);
        }
        if (b > 1)
        hm.put(b, 1l);
        long pow = -2l;
        for (Long i : hm.keySet()) {
            long p = 0;
            for (long j = i; j <= n; j *= i)
            p += n / j;
            p /= hm.get(i);
            if (p < pow || pow == -2l)
            pow = p;
        }
        System.out.print(pow);
    }
}

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 badcw
 */
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 {
        long INF = 0x3f3f3f3f3f3f3f3fL;

        long cal(long n, long b) {
            long res = 0;
            if (n < 0) return -1;
            for (long i = b; n / i > 0; i *= b) {
                res += n / i;
            }
            return res;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long b = in.nextLong();
            long res = INF;
            for (long i = 2; i * i <= b; ++i) {
                int k = 0;
                while (b % i == 0) {
                    b /= i;
                    k++;
                }
                if (k != 0) {
                    res = Math.min(res, cal(n, i) / k);
                }
            }
            if (b != 1) {
                res = Math.min(res, cal(n, b));
            }
            out.println(res);
        }

    }
}

import java.util.*;
public class A
{
public static void main(String ar[])
{
Scanner s=new Scanner(System.in);
long n=s.nextLong();   long b=s.nextLong();   long z=1;    long count=0;
long c=0;

if(b%2==0)
     {   z=2; count=0;  }
      while(b%2==0 && b>1)
    {   b=b/2; z=2; count++;    }

for(int i=3;i<=(int)Math.sqrt(b);i++)
{
      if(b%i==0)
     {   z=i; count=0;
      while(b%i==0 && b>1)
       {b=b/i;  count++;}
     }
}
if(b>2)
 { z=b;   count=1; }
long r=z;   int j=1;
while(z<=n)
{
   c+=n/z;
   if(z<1000000000 && r<1000000000 && z*r>z)
    z=z*r;
   else if(Math.pow(z,j)<(double)1000000000000000000l)
    z=z*r;
   else
    break;
    j++;
}
c=c/count;
System.out.println(c);
}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.StringTokenizer;
public class HowmanyZerosandhowmanyDigits {
	static ArrayList<Integer> primes;
	static long b;
	//static double logB;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		StringTokenizer st;
		sieveLinear((int)10e6);
		long n;
		st = new StringTokenizer(br.readLine());
		n = Long.parseLong(st.nextToken());
		b = Long.parseLong(st.nextToken());
		HashMap<Long, Long> pfb = new HashMap<>();
		primefac(b, pfb);
		long p,t,pow,cnt;
		long zeros = Long.MAX_VALUE;
		for(Entry<Long, Long> e:pfb.entrySet()) {
			p = e.getKey();pow = e.getValue();
			t = p;
			cnt = 0;
			while(t<=n) {
				cnt += n/t;
				if(t*p<t)
					break;
				t*=p;
			}
			zeros = Math.min(zeros, cnt/pow);
		}
		out.println(zeros);
		out.flush();
	}
	static void primefac(long n, HashMap<Long, Long> hm){
		int i = 0;
		long p;
		while(n>1 && i<primes.size()) {
			p = primes.get(i++);
			long cnt = 0;
			while(n>1 && n%p == 0) {
				cnt++;
				n/=p;
			}
			if(cnt > 0)
				hm.put(p, cnt);
		}
		if(n != 1)
			hm.put(n, 1l);
	}
	static void sieveLinear(int N)
	{
		primes = new ArrayList<Integer>();
		int[] lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)
				if(p > curLP || p * i > N)
					break;
				else
					lp[p * i] = i;
		}
	}
}

import java.util.*;

public class TrailingLoves {

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

        long n = sc.nextLong();
        long b = sc.nextLong();

        HashMap <Long, Long> pf = primeFactors(b);

        long maxMult = Long.MAX_VALUE;
        for (long i : pf.keySet()) {
            long mult = calculate(i, n);

            //System.out.println(i + ": " + pf.get(i));
            //System.out.println(mult);

            maxMult = Math.min(maxMult, mult / pf.get(i));
        }

        System.out.println("\n" + maxMult);

        sc.close();
    }

    public static long calculate(long b, long n) {
        long cnt = 0;
        long curr = b;
        while (curr > 0 && curr <= n) {
            cnt += n / curr;

            //System.out.println(n + " " + curr + " " + Math.floor(n / curr) + " " + cnt);
            curr *= b;
        }

        return cnt;
    }

    public static HashMap <Long, Long> primeFactors(long n) {
        HashMap <Long, Long> pf = new HashMap<>();

        while (n % 2 == 0) {
            if (pf.get(2L) == null) {
                pf.put(2L, 1L);
            } else {
                pf.put(2L, pf.get(2L) + 1L);
            }

            n = n/2;
        }

        for (long i = 3; i <= Math.sqrt(n); i = i + 2) {
            while (n % i == 0) {
                if (pf.get(i) == null) {
                    pf.put(i, 1L);
                } else {
                    pf.put(i, pf.get(i) + 1);
                }
                n = n/i;
            }
        }

        if (n > 2)
            pf.put(n, 1L);

        return pf;
    }
}

import java.util.Scanner;

// C soln seen
public class TrailingLoves {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long n=scn.nextLong();
		long b=scn.nextLong();
		long ans=Long.MAX_VALUE;
		//System.out.println(ans+" aaaa");
		for(long i=2;i<=b;i++) {
			if(i*i>b) i=b;
			int count=0;
			while(b%i==0) {
				b/=i;
				count++;
			}
			if(count==0)
				continue;
			long mul=1,y=0;
			while(n/mul!=0) {
				mul*=i;
				//System.out.println(mul);
				y+=n/mul;
			}
			ans=Math.min(ans, y/count);
		}
		System.out.println(ans);
	}

}

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        long n = reader.nextLong();
        long b = reader.nextLong();
        System.out.println(process(n, b));
    }

    private static long process(long n, long b){
        int cnt = 0;
        long res = Long.MAX_VALUE, tmp = 0, mul = 1;
        for(long i = 2; i <= b; i++){
            if(1L * i * i >= b){
                i = b;
            }
            cnt = 0;
            while(b % i == 0){
                b /= i;
                cnt++;
            }
            if(cnt != 0){
                tmp = 0;
                mul = i;
                while(mul <= n){
                    tmp += (long) n / mul;
                    mul *= i;
                }
                res = Math.min(tmp / cnt, res);
            }
        }
        return res;
    }
}

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

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

		/**/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		/*/
		Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("src/c.in"))));
		/**/

		long n = sc.nextLong();
		long b = sc.nextLong();

		boolean[] comp = new boolean[1000001];
		for (int i = 2; i <= 1000; i++) {
			if (comp[i])
				continue;
			for (int j = i*i; j <= 1000000; j+=i)
				comp[j] = true;
		}
		TreeMap<Long, Integer> powers = new TreeMap<Long, Integer>();
		for (int i = 2; i <= 1000000; i++) {
			if (comp[i])
				continue;
			if (b%i==0) {
				powers.put((long)i, 0);
				while (b%i==0) {
					powers.put((long)i, powers.get((long)i)+1);
					b /= i;
				}
			}
		}
		if (b != 1) {
			powers.put(b, 1);
		}
		long ans = Long.MAX_VALUE;
		for (long p : powers.keySet()) {
			long p2 = p;
			long val = 0;
			while (p2 <= n) {
				val += n/p2;
				p2 *= p;
				if (p > Integer.MAX_VALUE)
					break;
			}
			ans = Math.min(ans, val/powers.get(p));
		}
		System.out.println(ans);
	}
}