n, k, m = map(int, input().split())
ans = 0
now = m
while now <= n:
    ans += n // now - (n - k) // now
    ans -= k // now
    now *= m
print(ans)