#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
long long n, b, cnt, cs[MAXN], prime[MAXN];
inline long long read() {
  long long X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
int main() {
  n = read();
  b = read();
  long long x = b;
  for (long long i = 2; i * i <= b; i++) {
    if (x % i == 0) {
      prime[++cnt] = i;
      while (x % i == 0) {
        x /= i;
        cs[cnt]++;
      }
    }
  }
  if (x > 1) {
    prime[++cnt] = x;
    cs[cnt]++;
  }
  long long ans = 1e18;
  for (int i = 1; i <= cnt; i++) {
    long long x = n, s = 0;
    while (x > 1) {
      s += x / prime[i];
      x /= prime[i];
    }
    ans = min(ans, s / cs[i]);
  }
  cout << ans << endl;
  return 0;
}
