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