#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, b;
  cin >> n >> b;
  long long i, count, ans = 1000000000000000002;
  for (i = 2; i <= b; i++) {
    if (i * i > b) i = b;
    count = 0;
    if (b % i == 0) {
      while (b % i == 0) {
        count++;
        b = b / i;
      }
      long long y = 0, p = n;
      while (p) {
        y += p / i;
        p = p / i;
      }
      ans = min(ans, y / count);
    }
  }
  cout << ans << endl;
}
