#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l, r, k, p, num;
  cin >> l >> r >> k;
  num = 1;
  int ans = 0;
  while (num <= r) {
    if (num >= l && num <= r) {
      cout << num;
      ans++;
    }
    num *= k;
    if (ans != 0) cout << endl;
    if (num % k != 0) break;
  }
  if (ans == 0) printf("-1\n");
  return 0;
}
