#include <bits/stdc++.h>
long long int power(int x, int y);
int main() {
  long long int l, r, k, x, y, sum, i, flag = 0;
  double low, high, dif;
  scanf("%I64d %I64d %I64d", &l, &r, &k);
  low = log10(l) / log10(k);
  x = low;
  dif = low - x;
  high = log10(r) / log10(k);
  y = high;
  for (i = x; i <= high; i++) {
    sum = power(k, i);
    if (sum > r) break;
    if (sum >= l && sum <= r) {
      flag = 1;
      printf("%I64d\n", sum);
    }
  }
  if (flag == 0) printf("-1");
  return 0;
}
long long int power(int x, int y) {
  long long int fact = 1, i;
  for (i = 0; i < y; i++) {
    fact *= x;
  }
  return fact;
}
