#include <bits/stdc++.h>
using namespace std;
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
vector<long long> PrimeFactorization(long long n) {
  vector<long long> res;
  long long t = n;
  for (long long i = 2; i * i <= t;) {
    if (n % i == 0)
      res.push_back(i), n /= i;
    else
      i++;
  }
  if (n != 1) res.push_back(n);
  return res;
}
int main() {
  long long n, b;
  cin >> n >> b;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> ps = PrimeFactorization(b);
  map<long long, long long> cnt;
  for (long long i = 0; i < ps.size(); i++) cnt[ps[i]]++;
  long long ans = 1e18;
  for (auto itr = cnt.begin(); itr != cnt.end(); itr++) {
    long long sum = 0;
    long long base = itr->first;
    long long radix = itr->first;
    while (true) {
      sum += n / base;
      if (n / radix >= base) {
        base *= radix;
      } else {
        break;
      }
    }
    ans = min(ans, sum / itr->second);
  }
  cout << ans << endl;
  return 0;
}
