#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long inf = 1e18;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, b;     cin >> n >> b;     long long i = 2;     long long ans = inf;     while (i <= b) {       if (i * i > b) i = b;       long long cnt = 0;       while (b % i == 0) {         b /= i;         cnt++;       }       if (cnt == 0) {         i++;         continue;       }       long long tmp = 0;       long long j = 1;       while (j <= n / i) {         j *= i;         tmp += n / j;       }       ans = min(ans, tmp / cnt);       i++;     }     cout << ans;     return 0;   }   