#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long l, r, k;
  cin >> l >> r >> k;
  long long ans = 1;
  bool h = 0;
  long long num = r;
  long long cnt = 0;
  while (num > 0) {
    cnt++;
    num /= k;
  }
  while (ans <= r && ans > 0 && cnt > 0) {
    if (ans <= r && ans >= l) {
      cout << ans << ' ';
      h = 1;
    }
    ans *= k;
    cnt--;
  }
  if (!h) cout << -1;
  cout << endl;
  return 0;
}
