#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const int N = 1e5 + 5, inf = 1e9 + 5;
long long add(long long x, long long y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, b;
  cin >> n >> b;
  vector<pair<long long, long long>> factors;
  for (long long i = 2; i * i <= b; ++i) {
    if (b % i == 0) {
      long long cnt = 0;
      while (b % i == 0) {
        b /= i;
        cnt++;
      }
      factors.emplace_back(i, cnt);
    }
  }
  if (b > 1) factors.emplace_back(b, 1);
  long long ans = std::numeric_limits<long long>::max();
  for (auto& x : factors) {
    long long power = 1;
    long long curr_ans = 0;
    for (long long i = 1;; i++) {
      if (i * log(x.first) > log(n)) break;
      power *= x.first;
      curr_ans += n / power;
    }
    ans = min(ans, curr_ans / x.second);
  }
  cout << ans << endl;
  return 0;
}
