#include <bits/stdc++.h>
using namespace std;
long long len(long long n, long long k) {
  long long x = n;
  long long cnt = 0;
  while (x) {
    ++cnt;
    x /= k;
  }
  return cnt;
}
int32_t main() {
  long long l, r, k;
  cin >> l >> r >> k;
  long long cnt = 0;
  long long ans = 1;
  for (long long i = 0; i < len(r, k); ++i) {
    if (ans >= l && ans <= r) {
      ++cnt;
      cout << ans << " ";
    }
    ans *= k;
  }
  if (cnt == 0) cout << -1;
}
