#include <bits/stdc++.h>
#define pi acos(-1.0 )
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int INF = 0x3f3f3f3f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn =1000000 + 10;
const LL mod = 1e9+7;
int pl=0;
PLL num[200];
LL prime[maxn];
bool vis[maxn];
map<LL, int> mp;
int tot;
void bre(LL n)
{
tot=0;
for(int i=1;i<=pl&&prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==0)
{
num[tot++].first=prime[i];
while(n%prime[i]==0)
{
n/=prime[i];
num[tot-1].second++;
}
}
if(n==1)
break;
}
if(n!=1)
{
num[tot].second++;
num[tot++].first=n;
}
}
void getprime()
{
for(int i=2;i<maxn;i++)
{
if(vis[i]==false)
{
prime[++pl]=i;
}
for(int j=1;j<=pl&&i*prime[j]<maxn;j++)
{
vis[i*prime[j]]=true;
if(i%prime[j]==0)
break;
}
}
}
LL solve(LL x, LL factor)
{
LL res=0;
while(x){
res += x/factor;
x /= factor;
}
return res;
}
int main()
{
fastio;
getprime();
LL n, b;
cin >> n >> b;
bre(b);
LL ans = LL_INF;
for(int i=0; i<tot; i++){
LL tmp1 = solve(n, num[i].first);
tmp1/=num[i].second;
ans = min(ans, tmp1);
}
cout << ans << '\n';
}