n, k, m = map(int, input().split()) up = 0 down = 0 curr = m while curr <= n: up += n // curr if curr <= n - k: down += (n - k) // curr if curr <= k: down += k // curr curr *= m print(max(0, up - down))