#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  long long l, r, k;
  cin >> l >> r >> k;
  bool flag = true;
  long long s = log(l) / log(k);
  long long e = log(r) / log(k);
  for (long long i = s; i <= e + 1; i++) {
    long long val = pow(k, i);
    if (val >= l && val <= r) {
      flag = false;
      cout << val << " ";
    }
  }
  if (flag) cout << -1;
}
