#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > prime(long long n) {
  vector<pair<long long, long long> > ans;
  long long count = 0;
  while (n % 2 == 0) {
    count++;
    n = n / 2;
  }
  if (count > 0) ans.push_back(make_pair((long long)2, count));
  for (long long i = 3; i <= sqrt(n); i = i + 2) {
    count = 0;
    while (n % i == 0) {
      count++;
      n = n / i;
    }
    if (count > 0) ans.push_back(make_pair(i, count));
  }
  if (n > 2) ans.push_back(make_pair((long long)n, (long long)1));
  return ans;
}
long long hpower(long long n, long long b) {
  long long ans = 0;
  long long a = b;
  while (1) {
    if (n / a == 0)
      break;
    else
      ans += n / a;
    n = n / a;
  }
  return ans;
}
long long solve(long long n, long long b) {
  long long ans = 1000000000000000000;
  vector<pair<long long, long long> > pr = prime(b);
  vector<long long> lt;
  for (int i = 0; i < pr.size(); i++) {
    long long temp = hpower(n, pr[i].first);
    temp = temp / pr[i].second;
    ans = min(ans, temp);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long n, b;
  cin >> n >> b;
  long long ans = solve(n, b);
  cout << ans << endl;
  ;
  return 0;
}
