#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, b;
  cin >> n >> b;
  long long k = b;
  long long ans = LONG_LONG_MAX;
  long long cnt = 0;
  for (long long j = 2; j * j <= b; j++) {
    cnt = 0;
    while (k % j == 0) {
      cnt++;
      k /= j;
    }
    if (cnt == 0) continue;
    long long cnt1 = 0;
    long long k1 = n;
    while (k1 > 0) {
      cnt1 += (k1 / j);
      k1 /= j;
    }
    ans = min(ans, 1LL * (cnt1 / cnt));
  }
  if (k > 1) {
    cnt++;
    long long cnt1 = 0;
    long long k1 = n;
    while (k1 > 0) {
      cnt1 += (k1 / k);
      k1 /= k;
    }
    ans = min(ans, 1LL * (cnt1 / cnt));
  }
  cout << ans << endl;
  return 0;
}
