#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  long long r, l;
  cin >> r >> l >> k;
  long long b = log(r) / log(k);
  long long e = log(l) / log(k);
  int flag = 0;
  for (long long i = b - 1; i <= e + 1; i++) {
    long long num = pow(k, i);
    if (num > l) break;
    if (num >= r && num <= l) {
      if (flag) {
        cout << " " << num;
      } else {
        cout << num;
      }
      flag = 1;
    }
  }
  if (!flag) {
    cout << -1;
  }
  cout << endl;
  return 0;
}
