while True:
try:
n,a = list(map(int,input().split()))
k = 0
fac = 1
while n != 1:
fac *= n
n-=1
while fac % a == 0: #能整除a^k就能整除a(a^k的因子)
k += 1
fac //= a
print(k)
except Exception:
break
from math import factorial as f
n, a = map(int, input().split())
for i in range(1, n):
if f(n) % (a ** i) == 0 and f(n) % (a ** (i + 1)) != 0:
print(i)
break