#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b;
  cin >> n >> b;
  long long ans = 1e18;
  for (long long i = 2; i <= b; ++i) {
    if ((long long)i * i > b) i = b;
    long long cnt = 0;
    while (b % i == 0) {
      b /= i;
      cnt++;
    }
    if (cnt == 0) continue;
    long long k = n, tmp = 0;
    while (k > 0) {
      tmp += k / i;
      k /= i;
    }
    ans = min(ans, (tmp / cnt));
  }
  cout << ans;
  return 0;
}
