#include <bits/stdc++.h>
using namespace std;
long long int n, b, x = 0;
long long int sol() {
  long long int ans = 1e18;
  vector<long long int> p;
  map<long long int, long long int> mp;
  for (long long int i = 2; i * i <= b; i++) {
    long long int c = 0;
    while (b % i == 0) {
      b /= i;
      c++;
    }
    if (c) {
      p.push_back(i);
      mp[i] = c;
    }
  }
  if (b > 1) {
    p.push_back(b);
    mp[b] = 1;
  }
  for (int i = 0; i < p.size(); i++) {
    long long int cnt = 0;
    x = n;
    while (x) {
      cnt += x / p[i];
      x /= p[i];
    }
    ans = min(ans, cnt / mp[p[i]]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> b;
  cout << sol() << endl;
}
