#include <bits/stdc++.h>
using namespace std;
long long cnt;
long long b[10000], c[10000];
int main() {
  ios::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  long long k = sqrt(m);
  for (long long i = 2; i <= k; i++) {
    if (m % i == 0) {
      b[++cnt] = i;
      while (m % i == 0) {
        m /= i;
        c[cnt]++;
      }
    }
  }
  if (m != 1) b[++cnt] = m, c[cnt]++;
  long long ans = 1e18;
  for (long long i = 1; i <= cnt; i++) {
    long long k = b[i];
    long long num = 0;
    while (1) {
      num += n / k;
      if (n / b[i] >= k)
        k = k * b[i];
      else
        break;
    }
    ans = min(num / c[i], ans);
  }
  cout << ans << endl;
  return 0;
}
