def fac(n):
    if n <= 2:
        return 2
    return fac(n-1) * n

def zhengchu(n, a):
    k = 0
    n = fac(n)
    while n % a == 0:
        k += 1
        n //= a
    return k

while True:
    try:
        n, a = map(int, input().split())
        res = zhengchu(n, a)
        print(res)
    except:
        break