#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int l, r, k;
  cin >> l >> r >> k;
  vector<long long int> v;
  for (long long int i = 0; pow(k, i) <= r; i++) {
    if (pow(k, i) >= l && pow(k, i) <= r) v.push_back(pow(k, i));
  }
  if (v.size() == 0)
    cout << -1;
  else {
    for (long long int i = 0; i < v.size(); i++) cout << v[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
