#include <bits/stdc++.h>
using namespace std;
std::vector<int> prime;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, b;
  cin >> n >> b;
  long long int zero = 0;
  std::vector<pair<long long int, long long int>> factors;
  long long int temp = b;
  for (long long int i = 2; i * i <= b && b > 0; ++i) {
    int pow = 0;
    while (b % i == 0) {
      pow++;
      b /= i;
    }
    if (pow > 0) factors.push_back({i, pow});
  }
  if (b != 1) factors.push_back({b, 1});
  long long int zeroes = LLONG_MAX;
  for (long long int i = 0; i < factors.size(); ++i) {
    long long int t = n;
    long long int cnt = 0;
    long long int start = factors[i].first;
    while (t > 0) {
      t /= start;
      cnt += t;
    }
    zeroes = min(zeroes, cnt / factors[i].second);
  }
  cout << zeroes << endl;
  return 0;
}
