#include <bits/stdc++.h>
using namespace std;
long long n;
long long b;
vector<long long> fact;
vector<long long> cntt;
signed main() {
  cin >> n >> b;
  for (long long i = 2; i * i <= b; i++) {
    if (b % i == 0) {
      fact.push_back(i);
      long long ct = 0;
      while (b % i == 0) {
        ct++;
        b /= i;
      }
      cntt.push_back(ct);
    }
  }
  if (b > 1) {
    fact.push_back(b);
    cntt.push_back(1);
  }
  long long minv = 1e18;
  for (long long i = 0; i < fact.size(); i++) {
    long long tt = fact[i];
    long long cnt = 0;
    long long nn = n;
    while (nn) {
      cnt += nn / tt;
      nn /= tt;
    }
    minv = min(minv, cnt / cntt[i]);
  }
  cout << minv << endl;
  return 0;
}
