#include <bits/stdc++.h>
using namespace std;
map<long long, long long> primes;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int n, b;
  cin >> n >> b;
  for (int i = 2; i <= int(sqrt(b)); ++i) {
    while (b % i == 0) {
      primes[i]++;
      b /= i;
    }
  }
  if (b != 1) {
    primes[b]++;
  }
  long long ans = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
  for (auto it : primes) {
    long long nn = n;
    long long ansi = 0;
    for (;;) {
      long long cur = nn / it.first;
      if (cur == 0) {
        break;
      }
      ansi += cur;
      nn /= it.first;
    }
    ans = min(ans, ansi / it.second);
  }
  cout << ans << endl;
  return 0;
}
