#include using namespace std; int64_t count(int64_t n, int64_t p) { if (n == 0) { return 0; } return n / p + count(n / p, p); } int main() { int64_t n, k, m; cin >> n >> k >> m; cout << count(n, m) - count(k, m) - count(n - k, m) << endl; return 0; }