#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
long long poten(long long n, int k) {
  long long ans;
  for (long long i = 0; i <= n; ++i) {
    if (pow(k, i) > n) {
      ans = (i - 1);
      break;
    }
  }
  return ans;
}
int main() {
  long long l, r;
  int k;
  cin >> l >> r >> k;
  long long aux = poten(l, k);
  long long aux2 = poten(r, k);
  if ((l > 1 and l < k and r > 1 and r < k) or
      (l > k and r > k and l > pow(k, aux) and r < pow(k, aux + 1))) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < 60; ++i) {
    if (pow(k, i) >= l and pow(k, i) <= r) v.push_back(pow(k, i));
  }
  for (int i = 0; i < v.size(); ++i) {
    cout << v[i] << " ";
  }
  return 0;
}
