#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b;
  cin >> n >> b;
  vector<long long> v;
  map<long long, long long> mp;
  for (long long i = 2; i * i <= b; i++) {
    while (b % i == 0) {
      if (!mp[i]) {
        v.push_back(i);
      }
      mp[i]++;
      b = b / i;
    }
  }
  if (b != 1) {
    mp[b]++;
    v.push_back(b);
  }
  long long ans = 999999999999999999;
  for (int i = 0; i < v.size(); i++) {
    long long x = v[i];
    long long num = n;
    long long sum = 0;
    while (num) {
      sum += num / v[i];
      num /= v[i];
    }
    sum /= mp[v[i]];
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}
