#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define S2(x,y) scanf("%d%d",&(x),&(y))
#define SL(x) scanf("%lld",&(x))
#define SL2(x) scanf("%lld%lld",&(x),&(y))
#define SS second
#define FF first
#define MOD 1000007
//int factors[100];
map<long long, int> factors;
int idx=0;
void findFactor(long long n){
while(n%2==0){
factors[2]++;
n = n/2;
}
for(int i=3; i<=sqrt(n); i += 2){
while(n%i==0){
factors[i]++;
n = n/i;
}
}
if(n>2)
factors[n]++;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt","r",stdin);
long long n,b;
cin>>n>>b;
findFactor(b);
//for(auto x: factors)
// cout<<x.first<<" "<<x.second<<endl;
long long mp,cnt(0),mn(LONG_MAX);
// for(auto x: factors){
// mp = x.first;
// }
// cout<<mp<<endl;
for(auto x: factors){
mp = x.first;
cnt = 0;
for(long long i=mp;n/i>=1;i = i*mp){
// cout<<i<<endl;
cnt += n/i;
}
//cout<<x.first<<" "<<cnt<<" "<<mn<<endl;
cnt = cnt / x.second;
mn = min(mn,cnt);
}
// map.rbegin()->first
cout<<mn<<endl;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgoKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSByZXAoaSxhLGIpIGZvcihpbnQgKGkpID0gKGEpOyAoaSkgPCAoYik7IChpKSsrKQojZGVmaW5lIGFsbCh2KSAodikuYmVnaW4oKSwodikuZW5kKCkKI2RlZmluZSBTKHgpIHNjYW5mKCIlZCIsJih4KSkKI2RlZmluZSBTMih4LHkpIHNjYW5mKCIlZCVkIiwmKHgpLCYoeSkpCiNkZWZpbmUgU0woeCkgc2NhbmYoIiVsbGQiLCYoeCkpCiNkZWZpbmUgU0wyKHgpIHNjYW5mKCIlbGx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