#include <bits/stdc++.h>
using namespace std;
long long a[10000000];
long long c[10000000];
int main() {
  long long i, j, h;
  long long n, b;
  long long shuchu = 0;
  scanf("%lld %lld", &n, &b);
  long long top = 0;
  for (i = 2; i * i <= b; i++) {
    if (b % i == 0) {
      a[top] = i;
      while (b % i == 0) {
        b /= i;
        c[top]++;
      }
      top++;
    }
  }
  if (b > 1) {
    a[top] = b;
    c[top++] = 1;
  }
  long long Max = 1e18;
  for (i = 0; i < top; i++) {
    long long sum = 0;
    long long temp = n;
    while (temp) {
      sum += temp / a[i];
      temp /= a[i];
    }
    Max = min(Max, sum / c[i]);
  }
  printf("%I64d\n", Max);
}
