Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!


-----Input-----

The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 10^18, 2 ≤ k ≤ 10^9).


-----Output-----

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).


-----Examples-----
Input
1 10 2

Output
1 2 4 8 
Input
2 4 5

Output
-1


-----Note-----

Note to the first sample: numbers 2^0 = 1, 2^1 = 2, 2^2 = 4, 2^3 = 8 lie within the specified range. The number 2^4 = 16 is greater then 10, thus it shouldn't be printed.

Difficulty: MEDIUM
Tags: Implementation

Complete search
Skill types: Complete search

Starter code:

Solutions:
(l, r, k) = [int(i) for i in input().split()]
x = 0
flag = True
for i in range(10 ** 100 + 100):
	x = k ** i
	if x >= l and x <= r:
		flag = False
		print(x, end=' ')
	elif x > r:
		break
print('-1' if flag == True else '')


import math
(l, r, k) = map(int, input().split())
a = math.ceil(math.log(l, k))
b = math.floor(math.log(r, k))
c = k ** a
if c > r:
	print(-1)
else:
	z = []
	temp = c
	while temp <= r:
		if temp >= l:
			z.append(temp)
			temp *= k
		else:
			print(-1)
			break
	print(*z)


import math
(l, r, k) = map(int, input().split())
base_l = math.floor(math.log(l, k))
base_r = math.ceil(math.log(r, k))
pwrs = []
base_k = k ** base_l
for i in range(base_l, base_r + 1):
	if r >= base_k >= l:
		pwrs.append(base_k)
	base_k *= k
if len(pwrs) == 0:
	print(-1)
else:
	for p in pwrs:
		print(p, end=' ')


(l, r, k) = map(int, input().split())
b = 1
p = False
while True:
	if b >= l and b <= r:
		p = True
		print(b, end=' ')
	elif b > r:
		break
	b *= k
if not p:
	print(-1)


(l, r, k) = map(int, input().split())
s = 1
while s < l:
	s *= k
if s > r:
	print(-1)
else:
	while s <= r:
		print(s, end=' ')
		s *= k


(l, r, k) = [int(i) for i in input().split()]
a = 1
f = 0
while a <= r:
	if l <= a <= r:
		print(a, end=' ')
		f = 1
	a *= k
if f == 0:
	print(-1)


__author__ = 'Utena'
(l, r, k) = map(int, input().split())
i = 0
t = []
t0 = 1
t1 = 0
while True:
	if t0 >= l and t0 <= r:
		t.append(str(t0))
		t1 += 1
	if t0 > r:
		break
	t0 = t0 * k
if t1 == 0:
	print(-1)
else:
	print(' '.join(t))


from math import log
(l, r, k) = [int(x) for x in input().split()]
e = 0
i = k ** e
while i < l:
	e += 1
	i = k ** e
j = 1
an = i
ns = ['-1']
while an <= r:
	if ns[0] == '-1':
		ns = []
	ns.append(str(an))
	j += 1
	aux = int(k ** (j - 1))
	an = i * aux
print(' '.join(ns))


(l, r, k) = input().split()
ll = int(l)
rr = int(r)
kk = int(k)
cur = 1
p = 0
for i in range(10000000):
	if cur >= ll and cur <= rr:
		p = 1
		print(cur, end=' ')
	if cur > rr:
		break
	cur *= kk
if p == 0:
	print(-1)


(l, r, k) = map(int, input().split())
i = 1
m = -1
while i < l:
	i *= k
while i <= r:
	print(i, end=' ')
	i *= k
	m = 1
if m == -1:
	print(m)


(l, r, k) = [int(x) for x in input().split()]
p = 1
ans = []
while p <= r:
	if l <= p:
		ans.append(p)
	p *= k
n = len(ans)
if n == 0:
	print('-1')
else:
	print(' '.join(map(str, ans[0:n])))


(l, r, k) = map(int, input().split())
print(*([k ** i for i in range(65) if l <= k ** i <= r] or [-1]))


(l, r, k) = map(int, input().split())
v = []
t = 1
while t <= r:
	if t >= l:
		v.append(t)
	t *= k
if len(v) == 0:
	print('-1')
else:
	print(' '.join(map(str, v)))


(l, r, k) = map(int, input().split())
p = 1
c = 0
while p <= r:
	if p >= l:
		print(p, end=' ')
		c += 1
	p *= k
if c == 0:
	print(-1)


from math import floor, log
(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
ans = []
s = floor(log(l, k))
while k ** s <= r:
	if k ** s >= l:
		ans.append(k ** s)
	s = s + 1
if len(ans) == 0:
	print(-1)
else:
	print(*ans)


import math
(l, r, k) = map(int, input().split())
if k > r:
	if l == 1:
		print(1)
	else:
		print(-1)
else:
	minp = int(math.log(l, k))
	maxp = int(math.log(r, k)) + 1
	arr = []
	for i in range(minp, maxp + 2):
		if k ** i >= l and k ** i <= r:
			arr.append(k ** i)
	if len(arr) == 0:
		print(-1)
	else:
		print(*arr)


(l, r, k) = map(int, input().split())
cur = 1
valid = 0
while cur < 1e+19:
	if cur > r:
		break
	if cur >= l and cur <= r:
		valid = 1
		print(cur)
	cur *= k
if valid == 0:
	print(-1)


import math
(l, r, k) = [int(x) for x in input().split()]
exists = False
for x in range(int(math.log(10 ** 18) / math.log(k)) + 1):
	value = k ** x
	if l <= value <= r:
		print(value, end=' ')
		exists = True
	if value > r:
		break
if not exists:
	print(-1)


(l, r, k) = list(map(int, input().split()))
t = 1
ok = 0
while t <= r:
	if t >= l:
		print(t, end=' ')
		ok = 1
	t *= k
if ok != 1:
	print(-1)


(l, r, k) = map(int, input().split())
cnt = 0
p = 1
for i in range(70):
	if l <= p <= r:
		print(p)
		p *= k
		cnt += 1
	elif p < l:
		p *= k
	else:
		break
if cnt == 0:
	print(-1)


import re
a = input()
b = re.findall('[0-9]+', a)
l = int(b[0])
r = int(b[1])
k = int(b[2])
sum = 1
ll = []
while 1:
	if sum > r:
		break
	if sum >= l:
		ll.append(sum)
	sum = sum * k
if len(ll) > 0:
	s = str(ll[0])
	if len(ll) > 1:
		for i in range(1, len(ll)):
			s = s + ' ' + str(ll[i])
	print(s)
else:
	print(-1)


line = input('')
int_list = [int(i) for i in line.split()]
l = int_list[0]
r = int_list[1]
k = int_list[2]
one = False
for b in range(0, 100000000):
	x = k ** b
	if x >= l and x <= r:
		one = True
		print('%d ' % x, end='')
	elif x > r:
		break
if not one:
	print('-1')


(l, r, k) = map(int, input().split())
x = 0
found = False
while k ** x <= r:
	if k ** x >= l:
		found = True
		print(k ** x, end=' ')
	x += 1
if found == False:
	print(-1)


(l, r, k) = map(int, input().split())
number = 1
hasPrinted = False
while number <= r:
	if number >= l:
		print(number)
		hasPrinted = True
	number *= k
if not hasPrinted:
	print(-1)


import math
(l, r, k) = [int(i) for i in input().split()]
x = l
p1 = -1
while x > 0:
	p1 += 1
	x //= k
p = p1
x = k ** p
count = 0
while x <= r:
	if l <= x <= r:
		print(x, end=' ')
		count += 1
	x *= k
if count == 0:
	print(-1)
print()


(l, r, k) = map(int, input().split())
i = 1
ans = 0
while i <= r:
	if l <= i <= r:
		print(i)
		ans += 1
	i *= k
if not ans:
	print(-1)


(l, r, k) = map(int, input().split())
u = 1
p = False
while u < l:
	u *= k
while u <= r:
	p = True
	print(u, end=' ')
	u *= k
if not p:
	print(-1)


import math
(l, r, n) = input().split()
(l, r, n) = (int(l), int(r), int(n))
p = math.log(l, n)
if p != int(p):
	p = int(p) + 1
else:
	p = int(p)
p = int(n ** p)
x = []
while 1:
	if p > r:
		break
	if p >= l:
		x.append(p)
	p *= n
x1 = len(x)
if x1 == 0:
	print(-1)
else:
	for i in range(x1):
		print(x[i])


(l, r, k) = [int(x) for x in input().split()]
t = 1
out = []
while t <= r:
	if t >= l:
		out.append(str(t))
	t *= k
if not out:
	out.append('-1')
print(' '.join(out))


(l, r, k) = map(int, input().split())
ans = []
if l == 1:
	ans.append(1)
i = k
while i <= r:
	if l <= i:
		ans.append(i)
	i *= k
if len(ans) == 0:
	print(-1)
else:
	for el in ans:
		print(el, end=' ')


qq = input().split()
l = int(qq[0])
r = int(qq[1])
k = int(qq[2])
mm = 1
ch = 0
while mm <= r:
	if mm >= l:
		print(mm, end=' ')
		ch = 1
	mm = mm * k
if ch == 0:
	print(-1)


(l, r, k) = list(map(int, input().split()))
t = 1
rez = []
for i in range(80):
	if l <= t <= r:
		rez.append(t)
	t *= k
if rez:
	print(*rez)
else:
	print(-1)


(l, r, k) = map(int, input().split(' '))
cnt = 0
k2 = 1
while k2 <= r:
	if k2 >= l:
		print(k2, end=' ')
		cnt += 11
	k2 *= k
if cnt == 0:
	print(-1, end='')
print('')


(lower, higher, number) = input().split()
(lower, higher, number) = (int(lower), int(higher), int(number))
lower_remain = lower
lower_order = 0
while lower_remain >= number:
	lower_remain = lower_remain / number
	lower_order += 1
if lower_remain != 1:
	lower_order += 1
higher_remain = higher
higher_order = 0
while higher_remain >= number:
	higher_remain = higher_remain / number
	higher_order += 1
if higher_order < lower_order:
	print('-1')
else:
	for j in range(lower_order, higher_order + 1):
		if pow(number, j) > higher:
			continue
		else:
			print(pow(number, j), end=' ')
	print('')


(l, r, k) = map(int, input().split())
p = 0
ans = -1
while k ** p < l:
	p += 1
ans = k ** p
if not (ans >= l and ans <= r):
	print(-1)
else:
	while ans >= l and ans <= r:
		print(ans)
		ans = ans * k


def main():
	(l, r, k) = map(int, input().split())
	ans = []
	x = 1
	while x <= r:
		if x >= l:
			ans.append(x)
		x *= k
	if ans:
		print(' '.join(map(str, ans)))
	else:
		print(-1)
main()


(l, r, k) = map(int, input().split())
x = 1
f = 0
while x <= r:
	if x >= l:
		print(x, end=' ')
		f = 1
	x *= k
if f == 0:
	print('-1')


from sys import stdin
from collections import defaultdict
from operator import itemgetter

def main():
	[l, r, k] = list(map(int, stdin.readline().split()))
	run(l, r, k)
	print('')

def run(l, r, k):
	s = k
	while s < l:
		s *= s
	while s >= l and s > 1:
		s //= k
	if s < l:
		s *= k
	if s > r:
		print('-1', end='', flush=True)
	while s <= r:
		print('{} '.format(s), end='', flush=True)
		s *= k
main()


(l, r, k) = map(int, input().split())
j = k
f = True
if l <= 1:
	print(1, end=' ')
	f = False
while k <= r:
	if l <= k <= r:
		print(k, end=' ')
		f = False
	k *= j
if f:
	print(-1)


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
ent = False
for i in range(0, 60):
	a = pow(k, i)
	if a >= l and a <= r:
		ent = True
		print(a, end=' ')
if not ent:
	print(-1)
else:
	print()


(l, r, x) = map(int, input().split())
result = []
y = 1
while y <= r:
	if y >= l:
		result.append(y)
	y *= x
if len(result) == 0:
	print(-1)
else:
	print(' '.join(map(str, result)))


s = input()
s = s.split(' ')
(l, r, k) = (int(s[0]), int(s[1]), int(s[2]))
i = 0
suc = False
while True:
	tmp = k ** i
	if l <= tmp <= r:
		suc = True
		print(tmp, end='')
		print(' ', end='')
	if tmp > r:
		break
	i += 1
if suc:
	print()
else:
	print('-1')


import time
(l, r, k) = (int(i) for i in input().split())
start = time.time()
a = []
if l == 1:
	a.append(1)
now = k
while now < l:
	now *= k
while now <= r:
	a.append(now)
	now *= k
if len(a) == 0:
	print(-1)
else:
	for i in a:
		print(i, end=' ')
	print()
finish = time.time()


(l, r, k) = [int(num) for num in input().split(' ')]
powers = []
expo = 0
while k ** expo <= r:
	power = k ** expo
	if power >= l:
		powers.append(str(power))
	expo += 1
if len(powers) == 0:
	print('-1')
else:
	print(' '.join(powers))


(l, r, k) = map(int, input().split())
no_list = []
no = 1
while True:
	if no > r:
		break
	if no >= l:
		no_list.append(str(no))
	no *= k
if no_list:
	print(' '.join(no_list))
else:
	print(-1)


import sys
v = [int(x) for x in input().split()]
f = False
pot = 1
for i in range(1, 64):
	if v[0] <= pot and pot <= v[1]:
		print('{0}'.format(pot), end=' ')
		f = True
	pot = pot * v[2]
if f == False:
	print(-1)


(l, r, k) = map(int, input().split())
now = 1
res = []
for i in range(0, 100):
	if now > r:
		break
	if now >= l:
		res.append(now)
	now *= k
if len(res) == 0:
	print(-1)
for i in res:
	print(i, end=' ')


(l, r, k) = list(map(int, input().split()))
x = 1
while x < l:
	x *= k
a = []
while x <= r:
	a.append(x)
	x *= k
print(-1 if not a else ' '.join(list(map(str, a))))


import math
(l, r, k) = map(int, input().split())
p = int(math.log(l, k))
if pow(k, p) < l:
	p = p + 1
a = pow(k, p)
if a > r:
	print(-1)
	quit()
a = int(a)
print(a, end='')
a = a * k
while a <= r:
	print(' ', a, sep='', end='')
	a = a * k


(l, r, k) = map(int, input().split())
flag = 1
n = 1
while n <= r:
	if n >= l:
		print(n, end=' ')
		flag = 0
	n *= k
if flag == 1:
	print(-1)


(l, r, k) = list(map(int, input().split()))
a = []
for i in range(60):
	b = pow(k, i)
	if b > r:
		break
	elif l <= b <= r:
		a.append(b)
if len(a) == 0:
	print(-1)
else:
	print(*a)


import math
k = 0
(a, c, b) = map(int, input().split())
m = int(math.log(a, b))
if a == 1 and c == 243 and (b == 3):
	print('1 3 9 27 81 243')
else:
	if b ** m < a:
		m = m + 1
	n = int(math.log(c, b))
	if b ** n > c:
		n = n - 1
	for i in range(m, n + 1):
		print(b ** i, end=' ')
		k = 1
	if k == 0:
		print('-1')


user_input = str(input()).split()
l = int(user_input[0])
r = int(user_input[1])
k = int(user_input[2])
i = 0
is_there = False
while True:
	k_power = k ** i
	if l <= k_power <= r:
		is_there = True
		print(k_power, end=' ')
	i += 1
	if k_power > r:
		break
if not is_there:
	print(-1)
print()


(l, r, k) = map(int, input().split())
v = []
cnt = 1
s = str(k)
length = len(s)
while 1:
	if cnt > r:
		break
	if cnt >= l:
		v.append(cnt)
	s2 = str(cnt)
	length2 = len(s2)
	tot = length + length2
	cnt *= k
if len(v) == 0:
	print(-1)
else:
	for i in v:
		print(i, end=' ')


I = lambda : map(int, input().split())
(l, r, k) = I()
li = []
i = 0
while pow(k, i) <= r:
	t = pow(k, i)
	i += 1
	if l <= t <= r:
		li = li + [t]
if len(li) == 0:
	exit(print('-1'))
print(*li)


from math import log, ceil
(l, r, k) = map(int, input().split())
(fps, fpe) = (int(ceil(log(l, k))), int(log(r, k)) + 1)
cpow = pow(k, fps)
if cpow < l:
	cpow *= k
i = 0
while cpow <= r:
	print(cpow, end=' ')
	cpow *= k
	i += 1
if not i:
	print(-1)


(a, b, c) = [int(i) for i in input().split()]
t = 1
while a > t:
	t = t * c
if t > b:
	print(-1)
while t <= b:
	print(t, end=' ')
	t = t * c


import math
(l, r, k) = map(int, input().split())
c = 0
p = 0
i = 1
while i <= r:
	if i >= l and i <= r:
		print(i)
		c = 1
	i *= k
if c == 0:
	print('-1')


from math import log

def kp(l, r, k):
	kp = k ** int(log(l, k))
	while kp < l:
		kp *= k
	if kp > r:
		yield (-1)
	else:
		while kp <= r:
			yield kp
			kp *= k
(l, r, k) = map(int, input().split())
print(' '.join(map(str, kp(l, r, k))))


x = input()
x = x.split()
l = int(x[0])
r = int(x[1])
k = int(x[2])
ans = 1
flag = 0
while ans <= r:
	if ans >= l:
		flag = 1
		print(ans, end=' ')
	ans *= k
if not flag:
	print('-1')


(l, r, k) = map(int, input().split())
n = 1
f = False
while n < l:
	n *= k
while n <= r:
	print(n, end=' ')
	f = True
	n *= k
if not f:
	print(-1)
else:
	print()


(l, r, k) = list(map(int, input().split(' ')))
t = 1
a = 0
Ans = []
while t <= r:
	if t >= l:
		a += 1
		Ans.append(t)
	t *= k
if a == 0:
	print(-1)
else:
	print(' '.join(map(str, Ans)))


(l, r, k) = map(int, input().split())
f = False
for i in range(1000):
	if l <= k ** i <= r:
		f = True
		print(k ** i, end=' ')
	if k ** i > r:
		break
if not f:
	print(-1)


(sl, sr, sk) = input().split(' ')
l = int(sl)
r = int(sr)
k = int(sk)
temp = 1
xD = ''
while True:
	if temp >= l and temp <= r:
		xD = xD + str(temp) + ' '
	if temp > r:
		break
	temp = temp * k
if len(xD) > 0:
	print(xD)
else:
	print(-1)


import sys
(l, r, k) = map(int, input().split())
p = 1
ans = 0
while p <= r:
	if p >= l:
		ans += 1
		print(p, end=' ')
	p *= k
if ans == 0:
	print(-1)


import math
(l, r, k) = map(int, input().split())
n = int(math.log(l, k))
x = k ** n
p = 0
while x <= r and x != -1:
	if x >= l:
		print(x)
		p += 1
	if k == 1:
		x = -1
	x *= k
if p == 0:
	print(-1)


(l, r, k) = map(int, input().split())
p = 1
ok = False
while p <= r:
	if l <= p:
		print(p, end=' ')
		ok = True
	p *= k
if ok:
	print('')
else:
	print(-1)


(l, r, n) = map(int, input().split())
num = 0
ans = 1
while ans < l:
	ans *= n
while ans <= r:
	print(ans, end=' ', flush=True)
	ans *= n
	num += 1
if num == 0:
	print(-1)


import math
(l, r, k) = map(int, input().split())
x = 0
l_a = list()
while True:
	a = k ** x
	if a >= l and a <= r:
		l_a.append(a)
	elif a >= r:
		break
	x += 1
if len(l_a) == 0:
	print(-1)
else:
	print(' '.join((str(x) for x in l_a)))


try:
	while True:
		(l, r, k) = map(int, input().split())
		x = 1
		ls = []
		while x <= r:
			if x >= l:
				ls.append(x)
			x *= k
		if ls:
			print(' '.join(map(str, ls)))
		else:
			print(-1)
except EOFError:
	pass


import math
txt = input()
nums = txt.split(' ')
l = int(nums[0])
r = int(nums[1])
k = int(nums[2])
q = 1
while q < l:
	q = q * k
if q > r:
	print('-1', end='')
	exit()
print('%d' % q, end='')
q = q * k
while q <= r:
	print(' %d' % q, end='')
	q = q * k


(a, b, k) = map(int, input().split())
f = 0
lst = []
for i in range(0, 65):
	x = k ** i
	if x >= a and x <= b:
		lst.append(x)
		f = 1
ans = -1
if f == 0:
	print(ans)
else:
	for i in range(0, len(lst) - 1):
		print(lst[i], end=' ')
	print(lst[len(lst) - 1])


tmp = input()
(l, r, k) = map(int, tmp.split())
cur = 1
flag = False
while cur <= r:
	if cur >= l:
		print(cur, end=' ')
		flag = True
	cur *= k
if flag:
	print()
else:
	print(-1)


(l, r, k) = map(int, input().split())
ki = 1
ok = 0
while ki <= r:
	if ki >= l and ki <= r:
		print(ki, end=' ')
		ok = 1
	ki = ki * k
if ok == 0:
	print('-1')


(l, r, k) = map(int, input().split())
ans = [k ** i for i in range(60) if l <= k ** i <= r]
print(*ans) if len(ans) > 0 else print(-1)


(l, r, k) = list(map(int, input().split()))
ans = []
for i in range(0, r + 1, 1):
	if k ** i > r:
		break
	else:
		pass
	if k ** i < l:
		pass
	else:
		ans.append(str(k ** i))
if len(ans) == 0:
	print(-1)
else:
	x = ' '.join(ans)
	print(x)


(l, r, k) = map(int, input().split())
x = 1
test = 1
for i in range(30000000):
	x = k ** i
	if l <= x and x <= r:
		print(x, end=' ')
		test = 0
	if x > r:
		break
if test == 1:
	print(-1)


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
cnt = 0
xx = 1
ans = ''
for i in range(100):
	if xx > r:
		break
	if l <= xx and xx <= r:
		ans = ans + str(xx) + ' '
		cnt += 1
	xx *= k
if cnt == 0:
	print('-1')
else:
	print(ans)


from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
l = nextInt()
r = nextInt()
k = nextInt()
res = [k ** i for i in range(65) if k ** i >= l and k ** i <= r]
if len(res) == 0:
	print(-1)
else:
	for i in res:
		print(i, end=' ')


from math import log, ceil

def solve(l, r, k):
	i = ceil(log(l, k))
	arr = []
	while 1:
		v = k ** i
		if v <= r and v >= l:
			arr.append(v)
		else:
			break
		i += 1
	return arr
(l, r, k) = map(int, input().split())
resp = solve(l, r, k)
if resp:
	print(' '.join([str(i) for i in resp]))
else:
	print('-1')


def calc(l, r, k):
	answ = []
	e = 1
	while e < l:
		e *= k
	if e > r:
		return [-1]
	while e <= r:
		answ.append(e)
		e *= k
	return answ
(l, r, k) = [int(i) for i in input().split()]
for elem in calc(l, r, k):
	print(elem, end=' ')
print()


(l, r, k) = map(int, input().split())
ans = 0
s = 1
while s < l:
	s *= k
while s <= r:
	print(s, end=' ')
	s *= k
	ans += 1
if not ans:
	print(-1)


from sys import *
from math import *
from string import *
from operator import *
from functools import *
from fractions import *
from collections import *
setrecursionlimit(10 ** 7)
dX = [-1, 1, 0, 0, -1, 1, -1, 1]
dY = [0, 0, -1, 1, 1, -1, -1, 1]
RI = lambda : list(map(int, input().split()))
RS = lambda : input().rstrip().split()
ans = []
(l, r, k) = RI()
val = 1
while val <= r:
	if val >= l:
		ans.append(val)
	val *= k
if len(ans):
	print(*ans)
else:
	print('-1')


from sys import stdout
(l, r, k) = map(int, input().split())
count = 0
i = 0
while k ** i <= r:
	if k ** i >= l:
		stdout.write(str(k ** i) + ' ')
		count += 1
	i += 1
if count == 0:
	stdout.write('-1')
stdout.write('\n')


(l, r, k) = [int(x) for x in input().split()]
ls = []
for x in range(10000):
	if k ** x > r:
		break
	ls.append(k ** x)
right = []
for x in ls:
	if l <= x and x <= r:
		right.append(str(x))
if len(right) == 0:
	print(-1)
else:
	print(' '.join(right))


length = 10
array = [[] for i in range(length)]
(l, r, k) = map(int, input().split())
val = 1
ls = list()
if l <= 1 <= r:
	ls.append('1')
for i in range(1, 100):
	val *= k
	if l <= val <= r:
		ls.append(str(val))
if ls:
	print(' '.join(ls))
else:
	print(-1)


(l, r, k) = map(int, input().split())
L = []
for i in range(10 ** 8):
	if k ** i >= l and k ** i <= r:
		L.append(k ** i)
	elif k ** i > r:
		break
l = len(L)
if l == 0:
	print(-1)
else:
	print(*L)


a = input()
a = a.split(' ')
mini = int(a[0])
maxi = int(a[1])
nbr = int(a[2])
score = 0
total = 0
retour = []
while nbr ** score <= maxi:
	nombre = nbr ** score
	if nombre >= mini and nombre <= maxi:
		total += 1
		retour.append(str(nombre))
	score += 1
if total == 0:
	print('-1')
else:
	print(' '.join(retour))


(l, r, k) = map(int, input().split())
kk = 1
ll = []
while kk <= r:
	if kk >= l:
		ll.append(kk)
	kk *= k
if ll == []:
	ll.append(-1)
print(*ll)


(l, r, k) = map(int, input().split())
s = 1
ans = []
while True:
	if s > r:
		break
	if s >= l and s <= r:
		ans.append(s)
	s = s * k
if len(ans) == 0:
	print(-1)
else:
	for i in ans:
		print(i, end=' ')
	print()


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
cont = 0
teste = True
while True:
	if k ** cont >= l and k ** cont <= r:
		print(k ** cont, end=' ')
		teste = False
	elif k ** cont > r:
		break
	cont += 1
if teste:
	print('-1')


(l, r, k) = map(int, input().split())
x = 1
while x < l:
	x *= k
a = []
while x <= r:
	a.append(x)
	x *= k
if len(a) == 0:
	print(-1)
else:
	print(*a)


a = [int(x) for x in input().split()]
l = a[0]
r = a[1]
k = a[2]
c = []
for i in range(100):
	if k ** i >= l and k ** i <= r:
		c.append(k ** i)
if len(c) == 0:
	print(-1)
else:
	for i in range(len(c)):
		print(c[i], end=' ')


cur = 1
cnt = 0
a = input()
t = a.split()
l = int(t[0])
r = int(t[1])
k = int(t[2])
for i in range(1, 1000000):
	if l <= cur <= r:
		print(cur)
		cnt += 1
	cur *= k
	if r < cur:
		break
if cnt == 0:
	print(-1)


(l, r, k) = map(int, input().split())
ok = True
for i in range(0, 60):
	if k ** i >= l:
		if k ** i <= r:
			ok = False
			print(str(k ** i), end=' ')
if ok == True:
	print(-1)


(l, r, k) = map(int, input().split())
expp = 1
ans = []
while True:
	if expp >= l and expp <= r:
		ans.append(expp)
	elif expp > r:
		break
	expp *= k
if len(ans) == 0:
	print('-1')
else:
	for it in ans:
		print(it, end=' ')
	print('')


a = list(map(int, input().split()))
i = 0
s = 0
while s < a[0]:
	s = pow(a[2], i)
	i = i + 1
i = i - 1
spis = []
k = 0
while k <= a[1]:
	spis.append(k)
	k = pow(a[2], i)
	i = i + 1
spis = spis[1:]
if len(spis) > 0:
	print(*spis)
else:
	print('-1')


a = list(map(int, input().split()))
c = 0
ans = 1
while ans <= a[1]:
	if ans >= a[0] and ans <= a[1]:
		if c == 0:
			print(ans, end='')
		else:
			print(' ', ans, end='')
		c = 1
	ans *= a[2]
if c == 0:
	print('-1')
else:
	print()


(l, r, k) = map(int, input().split(' '))
n = 1
num = 0
res = []
while n < l:
	n *= k
while n >= l and n <= r:
	res.append(n)
	n *= k
	num += 1
if num == 0:
	print(-1)
else:
	print(' '.join((str(x) for x in res)))


import sys
(l, r, k) = map(int, input().split())
kk = 1
while l > kk:
	kk *= k
f = True
while kk <= r:
	print(kk, end=' ')
	f = False
	kk *= k
if f:
	print(-1)


import sys, itertools, math, collections, random

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
(l, r, k) = map(int, input().split())
n = 1
f = False
while n < l:
	n *= k
while n <= r:
	print(n, end=' ')
	f = True
	n *= k
if not f:
	print(-1)
else:
	print()


import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(l, r, k) = get_ints()
score = 1
result = []
while score <= r:
	if l <= score <= r:
		result.append(score)
	score *= k
if len(result) == 0:
	print(-1)
	exit()
print(*result, sep=' ')


import sys, itertools, math, collections, random

def ia():
	return [int(i) for i in sys.stdin.readline().strip().split(' ')]

def ii():
	return int(sys.stdin.readline().strip())

def istr():
	return sys.stdin.readline().strip()
(l, r, k) = ia()
n = 1
f = 0
while n <= r:
	if n >= l:
		print(n, end=' ')
		f += 1
	n *= k
if f == 0:
	print(-1)
else:
	print()


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
p = 1
flag = False
while True:
	if p > r:
		break
	if p >= l and p <= r:
		flag = True
		print(p, end=' ')
	p *= k
if flag == False:
	print('-1')
print('')


import math
(l, r, k) = map(int, input().split())
p = math.log(l, k)
p1 = math.ceil(p)
p2 = pow(k, p1)
if p2 > r:
	print(-1)
else:
	s = 0
	while p2 <= r and p2 >= l:
		print(p2, end=' ')
		p2 = p2 * k
		s = s + 1
	if s == 0:
		print(-1)


tree = input().split(' ')
tree = list(map(int, tree))
out = []
if tree[2] > tree[1] and tree[2] ** 0 < tree[0]:
	out = [-1]
else:
	for inc in range(0, tree[1]):
		if tree[2] ** inc <= tree[1] and tree[2] ** inc >= tree[0]:
			out.append(tree[2] ** inc)
		elif tree[2] ** inc > tree[1]:
			break
out = sorted(list(set(out)))
if out == []:
	print(-1)
print(' '.join(map(str, out)))


(r, l, k) = map(int, input().split())
print(*([k ** exp for exp in range(70) if r <= k ** exp <= l] or [-1]))


import sys
for line in sys.stdin:
	(l, r, k) = line.split()
l = int(l)
r = int(r)
k = int(k)
p = 0
i = 1
res = 0
while i <= r and i <= 10 ** 18:
	i = k ** p
	if i >= l and i <= r:
		(print(i),)
		res = 1
	p += 1
if res == 0:
	print(-1)


(l, r, k) = map(int, input().split())
v = 1
out = []
while v <= r:
	if v >= l:
		out.append(v)
	v *= k
if out:
	print(*out)
else:
	print(-1)


x = input()
(a, b, c) = x.split()
l = int(a)
r = int(b)
k = int(c)
cur = 0
powi = 0
while cur < l:
	cur = k ** powi
	powi += 1
c = 0
while cur <= r:
	c += 1
	print(cur, end=' ')
	cur = k ** powi
	powi += 1
if c == 0:
	print(-1)


(l, r, k) = map(int, input().split())
x = list(filter(lambda t: l <= int(t) <= r, [str(k ** i) for i in range(256)]))
if len(x) == 0:
	print(-1)
else:
	print(' '.join(x))


def solve():
	(l, r, k) = list(map(int, input().split(' ')))
	lst = []
	count = 0
	while k ** count <= r:
		if k ** count >= l:
			lst.append(k ** count)
		count += 1
	if len(lst) == 0:
		print(-1)
	else:
		print(' '.join([str(x) for x in lst]))
solve()


(l, r, k) = input().split()
(l, r, k) = (int(l), int(r), int(k))
exponent = 1
powers = list()
while exponent <= r:
	if exponent >= l:
		powers.append(exponent)
	exponent *= k
if not len(powers):
	powers.append(-1)
output = ''
for i in powers:
	output += str(i) + ' '
print(output[:-1])


(l, r, k) = map(int, input().split())
cnt = 0
flag = False
while k ** cnt < l:
	cnt += 1
while l <= k ** cnt <= r:
	flag = True
	print(k ** cnt, end=' ')
	cnt += 1
if not flag:
	print(-1)


(l, r, k) = map(int, input().split())
res = []
for i in range(10000):
	if k ** i >= l and k ** i <= r:
		res.append(k ** i)
	if k ** i > r:
		break
if res == []:
	print(-1)
	quit()
print(' '.join(map(str, res)))


(l, r, k) = [int(i) for i in input().split()]
i = 0
g = True
while True:
	t = k ** i
	if t <= r and t >= l:
		g = False
		print(t, end=' ')
	elif t > l:
		break
	i += 1
if g:
	print(-1)


import sys
import math
for line in sys.stdin:
	(l, r, k) = map(lambda x: int(x), line.split())
	out = []
	for i in range(math.ceil(r / 2)):
		c = k ** i
		if c in range(l, r + 1):
			out.append(str(c))
		elif c > r + 1:
			break
	if len(out) == 0:
		print('-1')
	else:
		print(' '.join(out))


(l, r, k) = map(int, input().split())
i = 1
a = []
while i < l:
	i *= k
while i <= r:
	a += [str(i)]
	i *= k
print(' '.join(a) if a else -1)


z = input()
c = 0
yo = -1
check = 0
for p in z.split():
	if c == 0:
		l = p
		l = int(l)
	elif c == 1:
		m = p
		m = int(p)
	elif c == 2:
		n = p
		n = int(n)
	c = c + 1
i = 0
while pow(n, i) <= m:
	if pow(n, i) >= l:
		check = check + 1
		print(int(pow(n, i)), end=' ')
	i = i + 1
if check == 0:
	print(yo)


(l, r, k) = map(int, input().split())
p = 0
f = True
while True:
	if k ** p <= r:
		if k ** p >= l:
			print(k ** p, end=' ')
			f = False
	else:
		break
	p += 1
if f:
	print(-1)


import math
(l, r, k) = map(int, input().split())
l1 = math.ceil(math.log(l, k))
r1 = math.ceil(math.log(r, k))
if k ** r1 > r:
	r1 -= 1
if k ** l1 < l:
	l1 += 1
print(-1 if l1 > r1 else ' '.join([str(k ** i) for i in range(l1, r1 + 1)]))


s = input('')
(l, r, k) = [int(i) for i in s.split(' ')]
val = 1
cnt = 0
res = ''
while val <= r:
	if val >= l:
		if cnt > 0:
			res += ' '
		cnt += 1
		res += str(val)
	val *= k
if cnt == 0:
	print(-1)
else:
	print(res)


s = input()
l = int(s[0:s.find(' ')])
r = int(s[s.find(' ') + 1:s.rfind(' ')])
k = int(s[s.rfind(' ') + 1:len(s)])
flag = 0
for i in range(60):
	result = k ** i
	if result <= r and result >= l:
		print(result, end=' ')
		flag = 1
if flag == 0:
	print('-1')


(l, r, k) = map(int, input().split())
ans = []
for i in range(100):
	if k ** i >= l and k ** i <= r:
		ans.append(k ** i)
if len(ans) == 0:
	print(-1)
else:
	print(*ans)


(l, r, k) = map(int, input().split())
p = int(1)
a = []
while True:
	if l <= p <= r:
		a.append(p)
	p *= k
	if p > r:
		break
if len(a) > 0:
	for _ in a:
		print(_, end=' ')
else:
	print('-1')


(l, r, k) = map(int, input().split())
res = []
if k > r:
	print('-1' if l != 1 else '1')
	exit(0)
num = 1
while num < l:
	num *= k
while l <= num <= r:
	res.append(str(num))
	num *= k
print('-1' if len(res) == 0 else ' '.join(res))


(l, r, k) = map(int, input().split())
f = 0
t = 1
while t <= r:
	if t >= l:
		f = 1
		print(t)
	t *= k
if not f:
	print(-1)


def main():
	(l, r, k) = map(int, input().split())
	index = 1
	arr = []
	while index <= r:
		if index >= l and index <= r:
			arr.append(index)
		index = index * k
	if len(arr) == 0:
		print(-1)
	else:
		print(*arr)
	return
main()


(l, r, k) = tuple(map(int, input().split()))
n = 0
while k ** n < l:
	n += 1
b = 0
while k ** n <= r and k ** n >= l:
	print(k ** n, end=' ')
	n += 1
	b = 1
if not b:
	print(-1)


(l, r, k) = map(int, input().split())
i = 1
ok = False
while True:
	if i > r:
		break
	if i >= l and i <= r:
		ok = True
		print(i)
	i *= k
if ok == False:
	print(-1)


(l, r, k) = (int(i) for i in input().split())
x = k
ans = []
if l == 1:
	ans += [1]
while k <= r:
	if k >= l:
		ans += [k]
	k *= x
if len(ans) == 0:
	print(-1)
else:
	print(' '.join(list(map(str, ans))))


(l, r, k) = map(int, input().split())
kk = 1
ll = []
while kk <= r:
	if kk >= l:
		ll.append(kk)
	kk *= k
if len(ll) == 0:
	print(-1)
else:
	print(' '.join(map(str, ll)))


R = lambda : map(int, input().split())
(l, r, k) = R()
i = 1
res = []
while i <= r:
	if i >= l:
		res.append(i)
	i *= k
if len(res) > 0:
	print(*res)
else:
	print(-1)


import sys
(l, r, k) = map(int, input().split())
res = 1
if k == 1:
	if l == 1:
		print(1)
	else:
		print(-1)
	sys.exit()
ans = 0
while res < l:
	res *= k
while res <= r:
	print(res)
	ans += 1
	res *= k
if ans == 0:
	print(-1)


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
a = 1
ans = []
while a <= r:
	if a >= l:
		ans.append(str(a))
	a *= k
if len(ans) > 0:
	print(' '.join(ans))
else:
	print(-1)


(a, b, c) = map(int, input().split())
k = 1
ans = []
while k < a:
	k *= c
while k <= b:
	ans.append(k)
	k *= c
if len(ans) == 0:
	print('-1')
else:
	print(*ans)


import sys, threading
sys.setrecursionlimit(10 ** 6)
scan = lambda : map(int, input().split())
(l, r, k) = scan()
pow = 0
cnd = False
while k ** pow <= r:
	if l <= k ** pow:
		print(k ** pow, end=' ')
		cnd = True
	pow += 1
if not cnd:
	print(-1)
print('\n')


(l, r, k) = map(int, input().split(' '))
n = 1
cnt = 0
while n <= r:
	if n >= l:
		cnt += 1
		print(n)
	n *= k
if cnt == 0:
	print(-1)


(L, R, K) = input().split()
L = int(L)
R = int(R)
K = int(K)
power = 1
found = 0
while power <= R:
	if L <= power:
		found = 1
		print(power, end=' ')
	power *= K
if found == 0:
	print(-1)


(limMin, limMax, number) = input().split()
limMin = int(limMin)
limMax = int(limMax)
number = int(number)
index = 0
powered = []
while number ** index <= limMax:
	if number ** index >= limMin:
		powered.append(number ** index)
	index += 1
if len(powered) < 1:
	print(-1)
else:
	result = ''
	for i in range(len(powered)):
		result = result + str(powered[i])
		if i < len(powered) - 1:
			result = result + ' '
	print(result)


a = []
d = input().split()
l = int(d[0])
r = int(d[1])
k = int(d[2])
t = 1
a.append(t)
while t < 10 ** 20:
	t *= k
	a.append(t)
cnt = 0
res = ''
for i in range(len(a)):
	if a[i] <= r and a[i] >= l:
		res += str(a[i]) + ' '
if len(res) <= 0:
	print(-1)
else:
	print(res)


(l, r, n) = tuple(map(int, input().strip().split()))
ans = []
temp = 1
while temp <= r:
	if temp >= l and temp <= r:
		ans.append(temp)
	temp *= n
if len(ans):
	for i in ans:
		print(i, end=' ')
else:
	print(-1)


(l, r, k) = map(int, input().split())
start = 1
ls = []
while 1:
	if start >= l and start <= r:
		ls.append(start)
	start *= k
	if start > 1e+18:
		break
if len(ls) == 0:
	print(-1)
	exit(0)
for item in ls:
	print(item, end=' ')


import sys
(l, r, k) = list(map(int, input().split()))
n = 1
f = True
while n <= r:
	if n >= l:
		sys.stdout.write(str(n) + ' ')
		f = False
	n *= k
if f:
	sys.stdout.write('-1')


(l, r, k) = map(int, input().split())
found = False
exp = 0
n = k ** exp
while n <= r:
	if n >= l:
		print(n)
		found = True
	exp += 1
	n = k ** exp
if not found:
	print(-1)


import sys
arr = list(map(int, input().split()))
l = arr[0]
r = arr[1]
k = arr[2]
found = 0
start = 1
if l == 1:
	start = 1
	print(start, '', end='')
	found = 1
while start <= r:
	start *= k
	if start >= l and start <= r:
		print(start, '', end='')
		found = 1
if found == 0:
	print('-1')


(l, r, k) = map(int, input().split())
li = []
for i in range(0, r):
	p = k ** i
	if l <= p <= r:
		li.append(p)
	elif p > r:
		break
if len(li) == 0:
	print('-1')
else:
	print(' '.join(map(str, li)))


(l, r, k) = map(int, input().split())
x = 1
ans = 0
f = 0
while x <= r:
	if l <= x and x <= r:
		print(x, end=' ')
		f = 1
	if x <= r // k:
		x = x * k
	else:
		break
if f == 0:
	print('-1')


import math
(l, r, k) = map(int, input().split())
first = k ** math.ceil(math.log(l, k))
if first > r or first < l:
	print(-1)
	exit()
while first <= r:
	print(first, end=' ')
	first *= k


first = True
power = 1
(a, b, c) = input().split(sep=' ')
(a, b, c) = (int(a), int(b), int(c))
while power <= b:
	if not first:
		print(' ', end='')
	if power >= a:
		print(power, end='')
		first = False
	power *= c
if first:
	print(-1, end='')
print('\n')


(l, r, k) = map(int, input().split())
i = 1
b = False
while i <= r:
	if l <= i:
		print(i, end=' ')
		b = True
	i *= k
if not b:
	print(-1)


from sys import stdin, stdout, stderr, exit
from math import log

def readil():
	return list(map(int, stdin.readline().strip().split()))

def main():
	(l0, r0, k) = readil()
	l = int(log(l0, k))
	r = int(log(r0, k))
	if r - l == 0 and (pow(k, l) > r0 or pow(k, l) < l0):
		stdout.write('-1')
		exit(0)
	for i in range(l - 1, r + 2):
		if pow(k, i) <= r0 and pow(k, i) >= l0:
			stdout.write(str(pow(k, i)) + ' ')
main()


k = 1
(a, b, c) = map(int, input().split(' '))
for i in range(1000):
	if c ** i > b:
		break
	if a <= c ** i <= b:
		print(c ** i, end=' ')
		k = 0
if k == 0:
	quit()
print(-1)


(l, r, k) = map(int, input().split())
q = k
f = -1
if l == 1:
	print(1, end=' ')
	f = 1
while k <= r:
	if k >= l and k <= r:
		print(k, end=' ')
		f = 1
	k *= q
if f == -1:
	print(f)


from collections import Counter, defaultdict, deque
import math
import sys
input = sys.stdin.readline

def solve():
	(l, r, k) = [int(x) for x in input().split()]
	ok = 0
	for i in range(100):
		p = k ** i
		if l <= p <= r:
			print(p, end=' ')
			ok = 1
		if p > r:
			break
	if not ok:
		print(-1)
tt = 1
for test in range(tt):
	solve()


(l, r, k) = [int(x) for x in input().split()]
ans = []
a = 1
while a <= r:
	if a >= l:
		ans.append(a)
	a *= k
if ans:
	for num in ans:
		print(num, end=' ')
else:
	print(-1)


(l, r, k) = map(int, input().split())
p = []
app = False
for i in range(61):
	if k ** i >= l:
		app = True
	if k ** i > r:
		break
	if app:
		p.append(k ** i)
if len(p) == 0:
	print(-1)
else:
	print(' '.join(map(str, p)))


import math
(l, r, k) = map(int, input().split())
x = int(math.log(l, k))
j = k ** x
t = 0
while j <= r and j >= l:
	print(k ** x, end=' ')
	x = x + 1
	j = k ** x
	t = 1
x = x + 1
j = k ** x
if t == 0:
	while j <= r and j >= l:
		print(k ** x, end=' ')
		x = x + 1
		j = k ** x
		t = 1
if t == 0:
	print('-1')


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
res = []
for i in range(r + 1):
	t = k ** i
	if l <= t <= r:
		res.append(t)
	if t > r:
		break
if len(res) != 0:
	for i in range(len(res)):
		res[i] = str(res[i])
	print(' '.join(res))
else:
	print(-1)


Ent = [int(i) for i in input().split()]
nums = list()
pot = 0
cond = False
while Ent[-1] ** pot <= Ent[1]:
	if Ent[-1] ** pot >= Ent[0]:
		cond = True
		nums.append(Ent[-1] ** pot)
	pot += 1
if cond:
	for i in range(len(nums)):
		if i != len(nums) - 1:
			print(nums[i], end=' ')
		else:
			print(nums[i])
else:
	print(-1)


(a, b, c) = map(int, input().split())
(d, e) = (0, [])
while c ** d <= b:
	if a <= c ** d <= b:
		e.append(str(c ** d))
	d += 1
if e == []:
	print(-1)
else:
	print(' '.join(e))


(l, r, k) = map(int, input().split())
ans = []
p = 1
while True:
	if l <= p <= r:
		ans += [p]
	if p > r:
		break
	p *= k
print(-1 if len(ans) == 0 else ' '.join((str(ans_i) for ans_i in ans)))


(l, r, k) = tuple(map(int, input().split()))
a = 1
c = 0
while a <= r:
	if a >= l and a <= r:
		print(a, end=' ')
		c += 1
	a = a * k
if c == 0:
	print(-1)


(l, r, k) = map(int, input().split())
ans = 0
i = 0
flag = 0
lis = []
while ans <= r:
	ans = pow(k, i)
	i = i + 1
	if ans >= l and ans <= r:
		lis.append(ans)
		flag = 1
if flag == 0:
	print('-1')
else:
	print(*lis)


(l, r, k) = input().split(' ')
l = int(l)
r = int(r)
k = int(k)
start = 1
fg = False
while start <= r:
	if start >= l and start <= r:
		fg = True
		print(start, end=' ')
	start = start * k
if fg == False:
	print('-1')


import sys
[l, r, k] = input().split()
l = int(l)
r = int(r)
k = int(k)
ans = 1
possible = 0
while ans < l:
	ans = ans * k
while ans >= l and ans <= r:
	print(ans, ' ', end='')
	possible = 1
	ans = ans * k
if possible == 0:
	print(-1)


from math import *
(l, r, k) = map(int, input().split())
start_pow = int(log(l, k))
start_val = int(pow(k, start_pow))
while start_val < l:
	start_val = start_val * k
if start_val > r:
	print('-1')
else:
	while start_val <= r:
		print(int(start_val), end=' ')
		start_val = start_val * k


(l, r, k) = list(map(int, input().split()))
res = 1
f = 0
while res <= r:
	if res >= l:
		print(res, end=' ')
		f = 1
	res *= k
if not f:
	print(-1)


(l, r, k) = map(int, input().split())
t = 1
ans = False
while t <= r:
	if t >= l:
		print(t, end=' ')
		ans = True
	t *= k
if not ans:
	print('-1')


(l, r, k) = map(int, input().split())
res = []
x = 1
while x <= r:
	if x >= l:
		res.append(x)
	x *= k
if res:
	print(*res)
else:
	print(-1)


import collections
import random
import sys
try:
	from tqdm import tqdm
except:

	def tqdm(iterable):
		return iterable
__taskname = ''
if __taskname:
	sys.stdin = open(__taskname + '.in')
	sys.stdout = open(__taskname + '.out', 'w')
(l, r, k) = list(map(int, input().split()))
(a, x, i) = ([], 1, 0)
while x <= r:
	if x >= l:
		a.append(x)
	x *= k
	i += 1
print(*(a if a else [-1]))


def tree(l, r, k):
	(t, lst) = (1, list())
	for i in range(80):
		if l <= t <= r:
			lst.append(t)
		t *= k
	if not lst:
		return [-1]
	return lst
(L, R, K) = [int(i) for i in input().split()]
print(*tree(L, R, K))


(l, r, k) = map(int, input().split())
res = []
a = 1
while a < l:
	a *= k
while a <= r:
	res.append(a)
	a *= k
if len(res) == 0:
	print('-1')
for i in res:
	print(i, end=' ')


(l, r, k) = map(int, input().split())
mas = []
j = 0
while k ** j <= r:
	if k ** j in range(l, r + 1):
		mas.append(str(k ** j))
	j += 1
print([' '.join(mas), '-1'][len(mas) == 0])


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
P = []
z = 1
x = 0
while z <= r:
	if z >= l:
		print(z, end=' ')
		x = 1
	z = z * k
if x == 0:
	print(-1)


import math

class StdReader:

	def read_int(self):
		return int(self.read_string())

	def read_ints(self, sep=None):
		return [int(i) for i in self.read_strings(sep)]

	def read_float(self):
		return float(self.read_string())

	def read_floats(self, sep=None):
		return [float(i) for i in self.read_strings(sep)]

	def read_string(self):
		return input()

	def read_strings(self, sep=None):
		return self.read_string().split(sep)
reader = StdReader()

def ceil_to_power(n, p):
	return p ** (n - 1).bit_length()

def floor_to_power(n, p):
	return p ** (n.bit_length() - 1)

def main():
	(l, r, k) = reader.read_ints()
	n = 1
	found = False
	while n <= r:
		if n >= l and n <= r:
			print(n, end=' ')
			found = True
		n *= k
	if not found:
		print(-1)
main()


(l, r, k) = map(int, input().split())
flag = 0
if l == 1:
	a = 1
	print(a)
	flag = 1
if k > r and flag == 0:
	print(-1)
else:
	a = k
	while a < l:
		a = a * k
	if a > r and flag == 0:
		print(-1)
	while a <= r:
		print(a)
		a = a * k


from math import log
(l, r, k) = map(int, input().split())
lower = int(log(l, k))
while k ** lower < l:
	lower += 1
if k ** lower > r:
	print(-1)
	exit()
print(k ** lower, end='')
lower += 1
while k ** lower <= r:
	print(' ' + str(k ** lower), end='')
	lower += 1
print()


(l, r, n) = map(int, input().split())
f = 0
for i in range(100):
	p = n ** i
	if p >= l and p <= r:
		f = 1
		print(p, end=' ')
if f == 0:
	print(-1)


(l, r, k) = [int(i) for i in input().split(' ')]
cnt = 0
aa = 1
d = 0
while aa:
	if k ** cnt >= l and k ** cnt <= r:
		d = 1
		print(k ** cnt, end=' ')
	if k ** cnt > r:
		aa = 0
	cnt += 1
if d == 0:
	print(-1)


(l, r, k) = map(int, input().split())
x = 1
printed = 0
while x <= r:
	if x >= l:
		print(x)
		printed = 1
	x = x * k
if printed == 0:
	print(-1)


inp = input().split()
(L, R, K) = (int(inp[0]), int(inp[1]), int(inp[2]))
if K is 1:
	print('{}'.format(1 if L is 1 else -1))
else:
	ans = []
	i = 1
	while i <= R:
		if i >= L:
			ans.append(i)
		i *= K
	if len(ans) is 0:
		print('-1')
	else:
		print(' '.join(map(str, ans)))


(l, r, k) = map(int, input().split())
s = ''
for i in range(500):
	if k ** i <= r and k ** i >= l:
		s += str(k ** i) + ' '
if len(s) > 0:
	print(s)
else:
	print(-1)


import math
lrk = [int(i) for i in input().split()]
l = lrk[0]
r = lrk[1]
k = lrk[2]
a = math.ceil(math.log(l, k))
b = round(math.log(r, k))
c = []
for i in range(a, b + 1):
	c.append(k ** i)
d = []
for i in c:
	if i <= r and i >= l:
		d.append(i)
if len(d):
	for i in d:
		print(i, end=' ')
else:
	print(-1)


(l, r, k) = map(int, input().split())
o = 1
t = 0
while o <= r:
	if o >= l:
		print(o, end=' ')
		t += 1
	o *= k
if t == 0:
	print(-1)


from math import ceil, floor, sqrt, log

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def dec_pow(a, n):
	res = 1
	while n > 0:
		if n % 2 == 1:
			res *= a
		a *= a
		n //= 2
	return res

def find_k_powers(l, r, k):
	m = 1
	res = []
	while m <= pow(10, 18):
		if m >= l and m <= r:
			res.append(m)
		m *= k
	if len(res) == 0:
		print(-1)
	print(*res, sep=' ')
t = 1
while t:
	t = t - 1
	(l, r, k) = map(int, input().split())
	find_k_powers(l, r, k)


(l, r, k) = map(int, input().split(' '))
i = 0
t = 1
a = []
while True:
	if t < l:
		t *= k
		continue
	elif l <= t <= r:
		a.append(t)
		t *= k
	else:
		break
if len(a):
	for i in range(len(a)):
		print(a[i], end=' ')
else:
	print(-1)


(l, r, k) = map(int, input().split())
ch = 1
suc = 0
if l == 1:
	print(ch, end=' ')
	suc += 1
while ch <= r:
	ch *= k
	if ch >= l and ch <= r:
		print(ch, end=' ')
		suc += 1
if suc == 0:
	print(-1)


(l, r, k) = map(int, input().split())
s = 1
while s < l:
	s *= k
ans = []
while s <= r:
	ans.append(s)
	s *= k
if ans:
	print(' '.join((str(v) for v in ans)))
else:
	print(-1)


(L, R, K) = map(int, input().split())
printed = False
cur = 1
while cur <= R:
	if cur >= L:
		if printed:
			print(' ', end='')
		print('{}'.format(cur), end='')
		printed = True
	cur *= K
if printed:
	print()
else:
	print(-1)


import sys
(L, R, K) = input().split(' ')
L = int(L)
R = int(R)
K = int(K)

def powersOf(K):
	i = 1
	while True:
		yield i
		i *= K
powers = []
for p in powersOf(K):
	if p < L:
		continue
	if p > R:
		break
	powers += [p]
if len(powers) == 0:
	print(-1)
else:
	print(' '.join(map(str, powers)))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(L, R, K) = getInts()
	curr = 1
	ans = []
	while curr < L:
		curr *= K
	while curr <= R:
		ans.append(curr)
		curr *= K
	if ans:
		print(*ans)
	else:
		print(-1)
	return
solve()


from math import log
(l, r, k) = map(int, input().split())
start = int(log(l, k))
ans = []
if k ** start < l:
	start += 1
while k ** start <= r:
	ans.append(str(k ** start))
	start += 1
if len(ans) == 0:
	ans.append('-1')
print(' '.join(ans))


(l, r, k) = map(int, input().split())
it = 0
out = ''
while True:
	v = k ** it
	if v >= l and v <= r:
		out += str(v) + ' '
	elif v > r:
		break
	it += 1
if out == '':
	print('-1')
else:
	print(out)


(l, r, w) = map(int, input().split())

def y(l, r, w):
	if w == 1:
		if l == 1:
			print('1')
		else:
			print('-1')
		return
	cnt = 0
	wn = 1
	while wn < l:
		wn *= w
	while wn >= l and wn <= r:
		print(wn, end=' ')
		wn *= w
		cnt += 1
	if cnt == 0:
		print('-1')
	else:
		print()
y(l, r, w)


def pow(num, n):
	ans = 1
	while n > 0:
		ans *= num
		n -= 1
	return ans
(l, r, k) = map(int, input().split())
i = 0
while pow(k, i) < l:
	i += 1
count = 0
a = []
while l <= pow(k, i) <= r:
	a.append(int(pow(k, i)))
	count += 1
	i += 1
if count == 0:
	print(-1)
else:
	for i in range(count):
		print(a[i], end=' ')


(l, r, k) = [int(i) for i in input().split()]
i = 1
hp = 0
while i <= r:
	if i >= l:
		print(i, end=' ')
		hp += 1
	i = i * k
if hp == 0:
	print(-1)


(l, r, k) = map(int, input().split())
t = 0
for x in range(100000):
	if k ** x >= l and k ** x <= r:
		print(k ** x, end=' ')
		t = 1
	elif k ** x > r:
		break
if t == 0:
	print(-1)


(l, r, k) = [int(i) for i in input().split()]
s = ''
t = 1
for i in range(10000):
	if t < l:
		t *= k
		continue
	if t > r:
		break
	s += str(t) + ' '
	t *= k
if not s:
	s = '-1 '
print(s[:-1])


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
ans = ''
fl = False
for i in range(0, 1000):
	if k ** i >= l and k ** i <= r:
		ans += str(k ** i) + ' '
if len(ans) == 0:
	print(-1)
else:
	print(ans)


(l, r, k) = [int(it) for it in input().split(' ')]
res = []
v = 1
while v <= r:
	if v >= l:
		res.append(v)
	v *= k
if len(res) > 0:
	print(' '.join(map(str, res)))
else:
	print(-1)


(inicio, fim, passo) = [int(num) for num in input().split(' ')]
c = 0
ver = False
while True:
	passo_c = pow(passo, c)
	c += 1
	if passo_c > fim:
		break
	elif inicio <= passo_c <= fim:
		print(f'{passo_c}', end=' ')
		ver = True
if ver == False:
	print('-1')


(l, r, k) = map(int, input().split())
now = 1
count = 0
while now < l:
	now *= k
while now <= r:
	print(now, end=' ')
	count += 1
	now *= k
if count == 0:
	print(-1)


import math
inp = input().split()
(l, r, n) = (int(inp[0]), int(inp[1]), int(inp[2]))
(curr, found) = (1, False)
for i in range(round(math.log(r, n)) + 1):
	if i > 0:
		curr *= n
	if l <= curr and curr <= r:
		print(int(curr), end=' ')
		found = True
if not found:
	print(-1)
else:
	print()


(l, r, base) = map(int, input().split())
k = 1
printed = False
while k <= r:
	if l <= k:
		print('%d ' % k, end='')
		printed = True
	k *= base
if not printed:
	print(-1)


def fast(k, x):
	if x == 0:
		return 1
	elif x % 2 == 1:
		return fast(k, x - 1) * k
	else:
		t = fast(k, x / 2)
		return t * t
(l, r, k) = map(int, input().split())
was = False
x = 0
ans = []
while True:
	now = fast(k, x)
	if now <= r:
		if now >= l:
			was = True
			ans.append(now)
	else:
		break
	x += 1
if was == False:
	print(-1)
else:
	print(*ans)


(l, r, k) = map(int, input().split())
ran = range(l, r + 1)
answer = [k ** e for e in range(100) if k ** e in ran]
if len(answer) > 0:
	print(*answer)
else:
	print(-1)


r = input()
(l, r, k) = r.split()
l = int(l)
r = int(r)
k = int(k)
if k == 1:
	if l == 1:
		print('1')
	else:
		print('-1')
else:
	m = 1
	cnt = 0
	while m <= r:
		if m >= l:
			print(m, end=' ')
			cnt = cnt + 1
		m *= k
	if cnt == 0:
		print(-1)


(l, r, k) = map(int, input().split())
p = 1
res = []
while p <= r:
	if l <= p <= r:
		res.append(p)
	p *= k
if len(res) == 0:
	print(-1)
else:
	for x in res:
		print(x, end=' ')


(l, r, k) = map(int, input().split())
a = 1
ans = []
while a <= r:
	if a >= l:
		ans.append(a)
	a *= k
if ans:
	print(*ans)
else:
	print(-1)


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial
from itertools import permutations

def bisector_left(arr, x):
	ind = -1
	s = 0
	e = len(arr) - 1
	while s <= e:
		m = s + (e - s) // 2
		if arr[m] < x:
			s = m + 1
		else:
			e = m - 1
			ind = m
	return ind

def bisector_right(arr, x):
	ind = -1
	s = 0
	e = len(arr) - 1
	while s <= e:
		m = s + (e - s) // 2
		if arr[m] <= x:
			s = m + 1
			ind = m
		else:
			e = m - 1
	return ind
(l, r, k) = mp()
v = []
for i in range(65):
	v.append(k ** i)
x = bisector_left(v, l)
y = bisector_right(v, r)
if x <= y:
	for i in range(x, y + 1):
		print(v[i], end=' ')
else:
	print(-1)


(l, r, k) = [int(x) for x in input().split()]
res = []
i = 0
while True:
	a = k ** i
	if a > r:
		break
	if a >= l:
		res.append(str(a))
	i += 1
if len(res) == 0:
	print(-1)
else:
	print(' '.join(res))


import math
vstup = input()
seznam = [int(n) for n in vstup.split()]
l = seznam[0]
r = seznam[1]
k = seznam[2]
a = math.log(l, k)
b = math.log(r, k)
y = int(b - a)
d = False
for c in range(y + 3):
	x = k ** int(a + c - 1)
	if x >= l and x <= r:
		print(x)
		d = True
if d == False:
	print(-1)
print(end=' ')


(l, r, k) = map(int, input().split())
if l == r and r == k:
	print(k)
	exit(0)
i = l
if l == r and k * k == r:
	print(r)
	exit(0)
fl = 0
cnt = 1
for j in range(l, r + 1):
	if j == 1:
		print(1)
		fl = 1
	cnt *= k
	if cnt > r:
		break
	if cnt >= l and cnt <= r:
		print(cnt, ' ')
		fl = 1
if fl == 0:
	print(-1)


[l, r, k] = [int(n) for n in input().split(' ')]
ans = []
kn = 1
while kn <= r:
	if l <= kn and kn <= r:
		ans.append(kn)
	kn = kn * k
if len(ans) == 0:
	print('-1')
else:
	print(' '.join([str(n) for n in ans]))


(l, r, k) = map(int, input().split())
ans = []
i = 1
while i <= 1e+18:
	if l <= i <= r:
		ans.append(i)
	i *= k
if ans:
	print(*ans)
else:
	print(-1)


(l, r, k) = map(int, input().split())
cur = 1
while cur < l:
	cur *= k
if cur > r:
	print(-1)
	exit()
while cur <= r:
	print(cur, end=' ')
	cur *= k


import math
(l, r, k) = input().split()
l = eval(l)
k = eval(k)
r = eval(r)
flag = 0
for i in range(70):
	u = pow(k, i)
	if u <= r and u >= l:
		if flag == 0:
			ans = str(u)
			flag = 1
		else:
			ans = ans + ' ' + str(u)
	elif u > r:
		break
if flag == 0:
	print(-1)
else:
	print(ans)


(l, r, k) = map(int, input().split())
z = 1
c = 0
while z <= r:
	if z <= r and z >= l:
		print(z, end=' ')
		c += 1
	z *= k
if c == 0:
	print(-1)


b = list(map(int, input().split(' ')))
l = b[0]
r = b[1]
k = b[2]
a = []
index = 0
step = 0
lon1 = -1
while lon1 <= r:
	if lon1 >= l and lon1 <= r:
		a.append(lon1)
		index += 1
	lon1 = k ** step
	step += 1
if index == 0:
	print(-1)
else:
	for i in range(index):
		print(a[i])


(l, r, k) = [int(x) for x in input().split()]
i = 0
x = 0
power = pow(k, i)
while power < l:
	i += 1
	power = pow(k, i)
while power <= r:
	print(power, end=' ')
	x += 1
	i += 1
	power = pow(k, i)
if x == 0:
	print(-1)
else:
	print()


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
val = 1
v = []
while val < l:
	val *= k
while val <= r and val >= l:
	v.append(val)
	val *= k
if len(v) == 0:
	print(-1)
else:
	for val in v:
		print(val, end=' ')
	print()


(l, r, k) = map(int, input().split())
op = []
um = k
if l == 1:
	op.append('1')
while um <= r:
	if um <= r and um >= l:
		op.append(str(um))
	um = um.__mul__(k)
if op == []:
	print(-1)
else:
	print(' '.join(op))


def print_powers(left_bound, right_bound, base):
	if left_bound > 1 and right_bound < base:
		print('-1')
		return
	x = 0
	while base ** x < left_bound:
		x += 1
	powers = []
	while base ** x <= right_bound:
		powers.append(base ** x)
		x += 1
	if len(powers) == 0:
		print('-1')
	else:
		print(' '.join([str(x) for x in powers]))
(l, r, k) = input().split()
(l, r, k) = (int(l), int(r), int(k))
print_powers(l, r, k)


(a, b, x) = map(int, input().split())
cont = 0
from math import log10
m = int(log10(a) / log10(x))
if pow(x, m) < a:
	m = m + 1
n = int(log10(b) / log10(x))
if pow(x, n) > b:
	n = n - 1
for i in range(m, n + 1):
	print(pow(x, i), end=' ')
	cont = cont + 1
if cont == 0:
	print('-1')


(l, r, k) = map(int, input().split())
mm = 1
while mm < l:
	mm *= k
ans = 0
while mm <= r:
	ans += 1
	print(mm, end=' ')
	mm *= k
if not ans:
	print(-1)
else:
	print()


(l, r, k) = map(int, input().split())
p = 0
ok = 1
while k ** p <= r:
	z = k ** p
	if z >= l and z <= r:
		ok = 0
		print(z, end=' ')
	p += 1
if ok == 1:
	print('-1')


(l, r, k) = map(int, input().split(' '))
ans = []
for i in range(70):
	if l <= k ** i and k ** i <= r:
		ans.append(k ** i)
if len(ans) > 0:
	print(' '.join(map(str, ans)))
else:
	print(-1)


(l, r, k) = map(int, input().split(' '))
m = 1
while m < l:
	m *= k
flag = False
while m <= r:
	flag = True
	print(m, end=' ')
	m *= k
if not flag:
	print('-1')


(l, r, k) = map(int, input().split())
ans = []
j = 0
from math import log
st = int(log(l) / log(k))
for i in range(st, 10000):
	if l <= k ** j <= r:
		ans.append(k ** j)
	if k ** j > r:
		break
	j += 1
if not ans:
	print(-1)
else:
	print(*ans)


def main():
	line = input()
	(l, r, k) = [int(x) for x in line.split(' ')]
	s = 1
	while s < l:
		s *= k
	if s > r:
		print(-1)
		return
	while s <= r:
		print(s, end=' ')
		s *= k
	print()
main()


import math
(l, r, k) = [int(x) for x in input().split()]
no_numbers = True
exp = int(math.log(l, k))
value = k ** exp
while True:
	if value >= l and value <= r:
		no_numbers = False
		print(value, end=' ', flush=True)
	if value > r:
		break
	value = value * k
if no_numbers:
	print(-1)


(l, r, k) = list(map(int, input().split()))
n = 1
ans = []
while n <= r:
	if l <= n <= r:
		ans.append(n)
	n *= k
if ans:
	print(*ans)
else:
	print(-1)


(l, r, k) = map(int, input().split())
x = 1
count = 0
li = []
while x <= r:
	if x >= l:
		li.append(x)
	x = x * k
if len(li) > 0:
	print(*li)
else:
	print(-1)


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
t = 1
ar = []
while t <= r:
	if t >= l and t <= r:
		ar.append(t)
	t *= k
if len(ar) == 0:
	print(-1)
else:
	print(*ar)


(l, r, k) = tuple(map(int, input().split()))
flag = 0
ans = 1
while ans <= r:
	if l <= ans:
		print(ans, end=' ')
		flag = 1
	ans *= k
if flag == 0:
	print('-1')


(l, r, k) = map(int, input().split())
x = 1
while x < l:
	x *= k
ok = False
while x >= l and x <= r:
	print(x, end=' ')
	ok = True
	x *= k
if not ok:
	print(-1)


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
ok = 0
for i in range(0, 62):
	if k ** i >= l and k ** i <= r:
		ok = 1
		print(k ** i, end=' ')
if ok == 0:
	print(-1)


(l, r, k) = [int(x) for x in input().split()]
a = 1
ok = False
while a <= r:
	if a >= l:
		ok = True
		print(a, end=' ')
	a = a * k
if ok == False:
	print(-1)


from math import log, ceil, floor
(l, r, k) = map(int, input().split())
all_powers = [str(k ** i) for i in range(ceil(log(l, k) - 1), floor(log(r, k) + 2)) if l <= k ** i <= r]
print(' '.join(all_powers) if all_powers else -1)


(l, r, k) = [int(i) for i in input().split()]
pot = [1]
while pot[0] < l:
	pot[0] *= k
while pot[len(pot) - 1] < r:
	pot.append(pot[len(pot) - 1] * k)
if pot[len(pot) - 1] != r:
	del pot[len(pot) - 1]
if pot == []:
	print(-1)
else:
	print(' '.join((str(i) for i in pot)))


(l, r, k) = map(int, input().split())
was = False
x = 0
ans = []
while True:
	now = k ** x
	if now <= r:
		if now >= l:
			was = True
			ans.append(now)
	else:
		break
	x += 1
if was == False:
	print(-1)
else:
	print(*ans)


import math
(l, r, k) = map(int, input().split())
flag = False
lbound = int(math.floor(math.log(l, k)))
ubound = int(math.ceil(math.log(r, k)))
for i in range(lbound, ubound + 1):
	x = k ** i
	if x >= l and x <= r:
		print(x, end=' ')
		flag = True
if flag == False:
	print('-1')


(l, r, k) = input().split()
(l, r, k) = (int(l), int(r), int(k))
n = 1
space = False
while n <= r:
	if n >= l:
		if space:
			print(' ', end='')
		else:
			space = True
		print(n, end='')
	n *= k
if space:
	print()
else:
	print(-1)


import math
(l, r, k) = map(int, input().split())
h = 0
for j in range(10 ** 9):
	if l <= k ** j <= r:
		print(k ** j, end=' ')
		h += 1
	elif k ** j > r:
		break
if h == 0:
	print(-1)


from sys import stdin, stdout
input = stdin.readline
(l, r, k) = map(int, input().split())
res = []
n = 1
while n <= r:
	if n >= l:
		res.append(str(n))
	n *= k
if len(res):
	stdout.write(' '.join(res))
else:
	stdout.write('-1')


entry = list(map(int, input().split()))
(l, r, k) = (entry[0], entry[1], entry[2])
numbers = []
i = 0
while k ** i <= r:
	if k ** i >= l:
		numbers.append(k ** i)
	i += 1
if numbers:
	for i in numbers:
		print(i, end=' ')
else:
	print(-1)


from math import log
(l, r, k) = map(int, input().split())
h = int(log(l) / log(k))
m = 1
for i in range(h, 1000000):
	if k ** i >= l and k ** i <= r:
		print(k ** i, end=' ')
		m = 0
	elif k ** i > r:
		break
if m:
	print(-1)


(l, r, k) = map(int, input().split())
p = 1
empty = True
while p <= r:
	if p >= l:
		print(p, end=' ')
		empty = False
	p *= k
if empty:
	print(-1)


arr = input().split(' ')
l = int(arr[0])
r = int(arr[1])
k = int(arr[2])
cur = int(1)
while cur < l:
	cur *= k
fl = False
ans = 0
while cur <= r:
	fl = True
	print(cur, end=' ')
	cur *= k
if fl == False:
	print(-1)


import math
(l, r, k) = map(int, input().split())
if r < k:
	if l == 1:
		print(1)
	else:
		print(-1)
else:
	if l <= k:
		if l == 1:
			start_k = 1
		else:
			start_k = k
	else:
		start_k = 1
	fl = False
	while start_k <= r:
		if start_k >= l:
			print(start_k, end=' ')
			fl = True
		start_k *= k
	if not fl:
		print(-1)


import math
arr = [int(x) for x in input().split()]
l = arr[0]
r = arr[1]
k = arr[2]
lower = int(math.floor(math.log2(l) / math.log2(k)))
upper = int(math.floor(math.log2(r) / math.log2(k)))
flag = 0
for i in range(lower, upper + 1):
	if k ** i >= l and k ** i <= r:
		flag = 1
		print(k ** i, end=' ')
if flag == 0:
	print('-1', end='')


(l, r, k) = map(int, input().split())
ls = []
i = 1
while i <= r:
	if i >= l:
		ls.append(i)
	i *= k
if len(ls):
	print(' '.join((str(i) for i in ls)))
else:
	print(-1)


(l, r, k) = map(int, input().split())
sols = []
i = 1
while i <= r:
	if i >= l:
		sols.append(str(i))
	i *= k
print(' '.join(sols) if len(sols) > 0 else '-1')


line = input().split(' ')
L = int(line[0])
R = int(line[1])
K = int(line[2])
base = 1
ans = []
seen = False
while base <= R:
	if base >= L:
		ans.append(str(base))
		seen = True
	base = base * K
if not seen:
	print('-1')
else:
	print(' '.join(ans))


(l, r, k) = map(int, input().split())
t = k
k = 1
c = 0
while k <= r:
	if k >= l:
		print(k, end=' ')
		c += 1
	k = k * t
if not c:
	print(-1)


(l, r, n) = [int(x) for x in input().split()]
f = 1
count = 0
while f <= r:
	if f >= l:
		print(f, end=' ')
		count += 1
	f *= n
if count == 0:
	print(-1)


import sys
(a, b, c) = map(int, sys.stdin.readline().split())
d = 1
g = 0
while d <= b:
	if d >= a:
		g = 1
		e = str(d)
		sys.stdout.write(e)
		sys.stdout.write(' ')
	d = d * c
if g == 0:
	print('-1')


(l, r, k) = input().strip().split()
s = 1
s = int(s)
l = int(l)
r = int(r)
k = int(k)
f = 0
for i in range(1000):
	if s >= l and s <= r:
		f = 1
		print(s)
	elif s > r:
		break
	s *= k
if f == 0:
	print(-1)


(a, b, c) = map(int, input().split())
count = -1
d = 0
l = []
q = 0
while d <= b:
	count += 1
	d = c ** count
	l.append(d)
for i in l:
	if a <= i <= b:
		print(i, end=' ')
		q = 1
if q == 0:
	print(-1)


def pow(x, y):
	if y == 0:
		return 1
	temp = pow(x, y // 2)
	if y % 2 == 0:
		return temp * temp
	else:
		return x * temp * temp
(l, r, k) = map(int, input().split())
i = 0
flag = 0
val = pow(k, i)
while val <= r:
	if val >= l:
		print(val, end=' ')
		flag = 1
	i = i + 1
	val = pow(k, i)
if flag == 0:
	print(-1)
print('\n')


(l, r, k) = [int(x) for x in input().split()]
fl = True
an = 1
while an <= r:
	if an >= l:
		fl = False
		print(an, end=' ')
	an = an * k
if fl is True:
	print(-1)


(l, r, k) = map(int, input().split())

def treepower(l, r, k):
	num = l
	box = []
	if k > r and l != 1:
		box = ['-1']
	else:
		for power in range(100):
			num = pow(k, power)
			if num < l:
				continue
			elif l <= num <= r:
				box.append(num)
			else:
				break
	return box
box = treepower(l, r, k)
out = ' '.join((str(i) for i in box))
if len(box) == 0:
	out = '-1'
print(out)


import itertools, functools, math

def solve():
	(l, r, k) = map(int, input().split())
	elems = []
	p = 1
	while p <= r:
		if l <= p:
			elems.append(p)
		p *= k
	if elems:
		return elems
	return [-1]
print(*solve())


(l, r, k) = [int(i) for i in input().split()]
go = 1
flag = False
while go <= r:
	if go >= l and go <= r:
		print(go, end=' ')
		flag = True
	go *= k
if not flag:
	print(-1)


import math
import sys
input = sys.stdin.readline
(l, r, k) = map(int, input().split())
f = int(math.log(l, k))
s = int(math.log(r, k)) + 1
if k ** f != l:
	f += 1
if f > s:
	print(-1)
	exit()
ans = []
for i in range(f, s + 1):
	if k ** i > r:
		break
	if k ** i < l:
		continue
	ans.append(k ** i)
if len(ans) == 0:
	print(-1)
	exit()
print(*ans)


(l, r, k) = map(int, input().split(' '))
(temp, c) = (1, 0)
while temp <= r:
	if temp >= l:
		print(temp)
		c += 1
	temp = temp * k
if c == 0:
	print('-1')


(n, m, k) = map(int, input().split())
temp = 1
t = False
for i in range(100):
	if temp >= n and temp <= m:
		print(temp, end=' ')
		t = True
	temp *= k
if not t:
	print(-1)


a = [int(x) for x in input().split()]
(x, y, z) = (a[0], a[1], a[2])
r = 1
v = []
while r <= y:
	if r >= x:
		v.append(r)
	r *= z
if len(v) == 0:
	print('-1')
else:
	print(*v)


(l, r, k) = map(int, input().split())
ans = []
kk = 1
while kk <= r:
	if l <= kk <= r:
		ans += [str(kk)]
	kk *= k
if ans == []:
	ans += ['-1']
print(' '.join(ans))


lrk = list(map(int, input().split()))
l = lrk[0]
r = lrk[1]
k = lrk[2]
i = 0
m = 0
while k ** i <= r:
	if k ** i >= l:
		print(k ** i, end=' ')
		m = m + 1
	i = i + 1
if m == 0:
	print(-1)


(l, r, k) = map(int, input().split())
curr = 1
while curr < l:
	curr *= k
out = []
while curr <= r:
	out.append(curr)
	curr *= k
if out:
	print(' '.join([str(x) for x in out]))
else:
	print('-1')


(l, r, k) = map(int, input().split())
z = 0
c = 0
while True:
	x = k ** z
	if x > r:
		break
	if l <= x:
		print(x, end=' ')
		c += 1
	z += 1
if c == 0:
	print('-1')


q = 1
for _ in range(q):
	(l, r, k) = map(int, input().split())
	i = 0
	x = 0
	while k ** i < l:
		x += 1
		i += 1
	j = x
	ans = []
	while k ** j <= r:
		ans.append(k ** j)
		j += 1
	if len(ans) == 0:
		print(-1)
	else:
		print(*ans)


(l, r, k) = map(int, input().split())
kol = 0
x = 1
while x <= r:
	if x >= l and x <= r:
		print(x, end=' ')
		kol += 1
	x = x * k
if kol == 0:
	print(-1)


(l, r, k) = map(int, input().split())
desi = 123
x = 0
while 1:
	if l <= k ** x <= r:
		desi = 786
		print(k ** x)
	if k ** x > r:
		break
	x += 1
if desi != 786:
	print(-1)


(l, r, k) = map(int, input().split())
n = 0
for i in range(64):
	a = k ** i
	if l <= a <= r:
		n += 1
		print(a, end=' ')
if n == 0:
	print('-1')


(l, r, k) = map(int, input().split())
sum = 1
f = 0
while 1:
	if sum >= l and sum <= r:
		print(sum, end=' ')
		f = 1
	if sum > r:
		break
	sum *= k
if not f:
	print('-1')


class Solution:

	def powerLink(self, l, r, k):
		Min = int(l / k)
		Max = int(r / k)
		stack = []
		for i in range(0, Max + 1):
			x = pow(k, i)
			if x > r:
				break
			if l <= x <= r:
				stack.append(x)
		return stack
(l, r, k) = list(map(int, input().split(' ')))
S = Solution()
result = S.powerLink(l, r, k)
if result == []:
	print(-1)
else:
	print(' '.join(list(map(str, result))))


(l, r, k) = map(int, input().split())
power = 1
ans = []
while power <= r:
	if power >= l:
		ans.append(power)
	power *= k
if ans:
	print(' '.join(map(str, ans)))
else:
	print('-1')


from math import *

def inp():
	return map(int, input().split())
(l, r, k) = inp()
(flag, beg, en) = (1, ceil(log(l, k)), ceil(log(r, k)))
for i in range(beg, en + 1, 1):
	if k ** i > r or k ** i < l:
		break
	print(k ** i, end=' ')
	flag = 0
if flag:
	print(-1)


(l, r, k) = map(int, input().split(' '))
x = 1
n = -1
while x <= r:
	if x >= l:
		print(x, end=' ')
		n = 1
	x = x * k
if n == -1:
	print(-1)


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
ar = []
i = 0
while True:
	p = k ** i
	if p > r:
		break
	if p >= l and p <= r:
		ar.append(p)
	i += 1
flag = True
for i in ar:
	print(i, end=' ')
	flag = False
if flag:
	print(-1)


(l, r, k) = map(int, input().split())
cur = 1
ans = []
while cur <= r:
	if cur >= l:
		ans.append(cur)
	cur *= k
if len(ans) == 0:
	print(-1)
else:
	print(*ans)


(l, r, k) = tuple(map(int, input().split()))
i = 0
x = False
while True:
	hi = k ** i
	if hi > r:
		break
	if hi in range(l, r + 1):
		x = True
		print(hi, end=' ')
	i += 1
if not x:
	print(-1)


import sys
(l, r, k) = [int(n) for n in input().split()]
ans = k
count = 0
if l == 1:
	print(1, end=' ')
	count += 1
elif k > r:
	print(-1)
	sys.exit()
while ans < l:
	ans *= k
while ans <= r:
	print(ans, end=' ')
	ans *= k
	count += 1
if count == 0:
	print(-1, end=' ')
print()


(l, r, k) = map(int, input().split())
ans = 1
output = ''
while ans <= r:
	if ans >= l:
		output = output + str(ans) + ' '
	ans = ans * k
if output == '':
	print('-1')
else:
	print(output)


def solve():
	(L, R, K) = map(int, input().split())
	k = 1
	out = []
	while k <= R:
		if k >= L:
			out.append(k)
		k *= K
	if len(out) == 0:
		print(-1)
	else:
		print(' '.join(map(str, out)))
solve()


(l, r, k) = list(map(int, input().split()))
ans = ''
found = False
i = 1
while i <= r:
	if l <= i <= r:
		found = True
		ans += str(i) + ' '
	i *= k
if not found:
	print(-1)
else:
	print(ans)


(s, f, n) = map(int, input().split())
p = 1
check = True
for i in range(100):
	if p >= s and p <= f:
		print(p)
		check = False
	p *= n
if check:
	print(-1)


l = input('').split(' ')
x = 1
c = 0
while x <= int(l[1]):
	if x >= int(l[0]):
		c = c + 1
		print(x, end=' ')
	x = x * int(l[2])
if c == 0:
	print('-1')


a = list(map(int, input().split()))
asd = False
lol = 10 ** 18
for i in range(lol):
	kek = a[2] ** i
	if kek <= a[1] and kek >= a[0]:
		print(str(kek))
		asd = True
	elif kek > a[1]:
		break
if not asd:
	print('-1')


from math import log
from math import ceil
(l, r, k) = map(int, input().split())
t = ceil(log(l, k))
if l == r:
	if k ** t != l:
		print(-1)
	else:
		print(l)
elif k ** t > r:
	print(-1)
else:
	s = k ** t
	L = []
	while s <= r:
		L.append(str(s))
		s *= k
	print(' '.join(L))


import math
(l, r, a) = list(map(int, input().split()))
i = 0
flag = False
while True:
	tmp = a ** i
	if l <= tmp and tmp <= r:
		flag = True
		print(tmp, end=' ')
	elif tmp > r:
		break
	i += 1
if flag == 0:
	print(-1)


(l, r, k) = [int(i) for i in input().split()]
hasAns = False
cur = 1
while cur <= r:
	if l <= cur <= r:
		print(cur, end=' ')
		hasAns = True
	cur *= k
if not hasAns:
	print(-1)


import math
(l, r, k) = map(int, input().split())
if l == 1:
	beginning = 0
else:
	beginning = math.floor(math.log(l, k))
if r == 1:
	ending = 0
else:
	ending = math.ceil(math.log(r, k))
ans = pow(k, beginning)
isans = False
if ans >= l and ans <= r:
	print(ans, end=' ')
	isans = True
for i in range(beginning + 1, ending):
	ans = ans * k
	print(ans, end=' ')
	isans = True
ans = ans * k
if ans <= r:
	print(ans)
	isans = True
if not isans:
	print(-1)


inp = input().split(' ')
left = int(inp[0])
right = int(inp[1])
base = int(inp[2])
powers = [1]
while powers[-1] < right:
	powers.append(powers[-1] * base)
outp = []
for i in powers:
	if left <= i and i <= right:
		outp.append(i)
if len(outp) == 0:
	print(-1)
else:
	for (i, val) in enumerate(outp):
		print(val, end='')
		if i == len(outp) - 1:
			print()
		else:
			print(' ', end='')


(l, r, k) = [int(x) for x in input().split()]
cur = 1
while cur < l:
	cur *= k
f = False
while cur <= r:
	print(cur, end=' ')
	f = True
	cur *= k
if not f:
	print(-1)


import sys
(l, r, k) = map(int, sys.stdin.readline().split())
s = 1
found = False
while s <= r:
	if s >= l:
		print(s, end=' ')
		found = True
	s = s * k
if found == False:
	print(-1)


(l, r, k) = map(int, input().split())
empty = True
for i in range(100):
	if k ** i >= l and k ** i <= r:
		print(k ** i, end=' ')
		empty = False
	if k ** i > r:
		break
if empty:
	print(-1)


import math
(l, r, k) = str(input()).split()
l = int(l)
r = int(r)
k = int(k)
xl = int(math.floor(math.log(l, k)))
xr = int(math.ceil(math.log(r, k)))
line = list()
for x in range(xl, xr + 1):
	v = k ** x
	if v < l:
		continue
	elif v > r:
		break
	else:
		line.append(str(v))
if len(line) > 0:
	print(' '.join(line))
else:
	print('-1')


(l, r, x) = input().split(' ')
l = int(l)
r = int(r)
x = int(x)
st = 1
bb = 0
while 1:
	if st >= l and st <= r:
		print(st, end=' ')
		bb = 1
	st *= x
	if st > r:
		break
if not bb:
	print(-1)


N = input().split()
x = 0
abdo = ''
for oba7 in range(3):
	N[oba7] = int(N[oba7])
while N[2] ** x < N[0]:
	x += 1
if N[2] ** x <= N[1]:
	while N[2] ** x <= N[1]:
		abdo = abdo + str(N[2] ** x) + ' '
		x += 1
	print(abdo)
else:
	print(-1)


from sys import stdout
(l, r, k) = map(int, input().split())
f = 1
v = 0
while f <= r:
	if f >= l:
		v = 1
		stdout.write(str(f) + ' ')
	f *= k
if v == 0:
	print(-1)


import math
inp = list(map(int, input().split()))
l = inp[0]
r = inp[1]
n = inp[2]
low = math.ceil(math.log2(l) / math.log2(n))
i = low
ans = pow(n, i)
v = []
while True:
	if ans < l or ans > r:
		break
	v.append(ans)
	ans = ans * n
if len(v) == 0:
	print(-1)
else:
	for x in v:
		print(x, end=' ')
	print()


(l, r, k) = map(int, input().split())
j = 1
b = 0
while j < l:
	j *= k
while j <= r:
	if j >= l and j <= r:
		b = 1
		print(j, end=' ')
	j = j * k
if b == 0:
	print(-1)


(l, r, k) = map(int, input().split())
p = []
e = 0
while k ** e <= r:
	p.append(k ** e)
	e += 1
flag = 0
for i in p:
	if i >= l and i <= r:
		print(i, end=' ')
		flag = 1
if flag == 0:
	print('-1')


(l, r, k) = map(int, input().split())
K = k
k = 1
cnt = 0
while k <= r:
	if k >= l:
		print(k, end=' ')
		cnt += 1
	k *= K
if cnt == 0:
	print(-1)


(l, r, k) = map(int, input().split())
status = False
ans = ''
for i in range(80):
	if k ** i >= l and k ** i <= r:
		status = True
		ans = ans + str(k ** i) + ' '
if status == False:
	ans += '-1'
print(ans)


(l, r, k) = map(int, input().split())
num = 1
fo = False
while num <= r:
	if num <= r and num >= l:
		print(num)
		fo = True
	num *= k
if not fo:
	print('-1')


(l, r, k) = map(int, input().strip().split())
i = 0
ans = 0
countt = 0
while 1:
	temp = pow(k, i)
	if temp > r:
		break
	if temp >= l and temp <= r:
		print(str(temp) + ' ', end='')
		countt += 1
	i += 1
if countt == 0:
	ans = -1
	print(ans)


(l, r, k) = map(int, input().split())
cur = 0
k1 = 1
while k1 < l:
	k1 *= k
while k1 <= r:
	print(k1, end=' ')
	cur += 1
	k1 *= k
if cur == 0:
	print(-1)


(l, r, k) = map(int, input().split())
acc = 1
answer = []
for i in range(100):
	if acc >= l and acc <= r:
		answer.append(acc)
	acc *= k
if len(answer) != 0:
	print(' '.join(map(str, answer)))
else:
	print(-1)


ii = input().split()
ii = [int(x) for x in ii]
(l, r, k) = ii
acc = 1
exist = False
while acc <= r:
	if acc >= l:
		print(acc, end=' ')
		exist = True
	acc *= k
if not exist:
	print(-1)


from math import log, floor
(l, r, n) = map(int, input().split())
p = floor(log(l, n))
a = []
i = n ** p
while i <= r:
	if l <= i:
		a.append(i)
	i *= n
if len(a) == 0:
	a = [-1]
print(*a)


(l, r, k) = [int(i) for i in input().split()]
a = []
t = 1
while t <= r:
	if t >= l:
		a.append(t)
	t *= k
if len(a) == 0:
	print(-1)
else:
	for elem in a:
		print(elem, end=' ')


(l, r, k) = tuple(map(int, input().split()))
ll = l
rr = r
m = 0
while l != 0:
	m += 1
	l = l // k
m = m - 1
n = 0
while r != 0:
	n += 1
	r = r // k
output = False
for i in range(n - m + 1):
	out = k ** (m + i)
	if out >= ll and out <= rr:
		print(out, end=' ')
		output = True
if output == False:
	print(-1)


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
i = 1
x = False
while i <= r:
	if i >= l:
		print(i)
		x = True
	i = i * k
if x == False:
	print(-1)


(l, r, k) = map(int, input().split())
x = 1
ans = ''
while x <= r:
	if x >= l:
		ans += str(x) + ' '
	x *= k
if ans == '':
	ans = '-1'
print(ans)


a = [int(i) for i in input().split()]
tmp = 1
L = []
while tmp <= a[1]:
	if tmp >= a[0]:
		L.append(tmp)
	tmp *= a[2]
if len(L) == 0:
	print(-1)
else:
	print(*L)


(l, r, k) = map(int, input().split())
cur = 1
flag = True
while cur <= r:
	if cur >= l and cur <= r:
		print(cur, end=' ')
		flag = False
	cur *= k
if flag:
	print(-1)


s = input().split()
l = int(s[0])
r = int(s[1])
k = int(s[2])
i = 1
some = False
while i <= r:
	if i >= l:
		print('%d ' % i, end='')
		some = True
	i = i * k
if not some:
	print('-1')


(l, r, k) = map(int, input().split())
f = [k ** i for i in range(61) if l <= k ** i <= r]
if len(f):
	for i in f:
		print(i, end=' ')
else:
	print(-1)


[l, r, k] = [int(x) for x in input().split()]
i = 1
b = 1
while True:
	if i > r:
		break
	if i >= l:
		b = 0
		print(i)
	i *= k
if b:
	print(-1)


(l, r, k) = map(int, input().split())
i = 0
flag = 0
temp = pow(k, i)
while temp <= r:
	if temp >= l:
		print('{} '.format(temp), end='')
		flag = 1
	i += 1
	temp = pow(k, i)
if flag == 0:
	print(-1)


def main():
	(l, r, k) = read()
	ct = 1
	printed = False
	while ct <= r:
		if ct >= l:
			write(ct)
			write(' ')
			printed = True
		ct *= k
	if not printed:
		return -1

def read(typ=int):
	input_line = input().strip()
	if typ is None:
		return input_line
	return list(map(typ, input_line.split()))

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


entrada = input().split()
min = int(entrada[0])
max = int(entrada[1])
numero = int(entrada[2])
cont = 0
printar = []
n = numero ** cont
while True:
	if n >= min and n <= max:
		printar.append(n)
		cont += 1
		n = numero ** cont
	elif n > max:
		break
	else:
		cont += 1
		n = numero ** cont
if len(printar) == 0:
	print(-1)
else:
	for i in range(len(printar)):
		print(printar[i], end=' ')


entrada = [int(x) for x in input().split()]
li = entrada[0]
ls = entrada[1]
base = entrada[2]
potencia = 0
achou = False
while True:
	if base ** potencia > ls:
		break
	if not base ** potencia < li:
		print(base ** potencia, end=' ')
		achou = True
	potencia += 1
if not achou:
	print(-1)


def x():
	(l, r, k) = [int(s) for s in input().split()]
	res = k
	if l == 1:
		yield 1
	while k <= r:
		if l <= k <= r:
			yield k
		k *= res
		if k > r:
			break
d = [i for i in x()]
if len(d):
	print(*d)
else:
	print(-1)


(l, r, k) = map(int, input().split())
now = 1
ok = 0
while now <= r:
	if now >= l:
		print(now, ' ')
		ok = 1
	now *= k
if ok == 0:
	print(-1)


(l, r, k) = map(int, input().split())
print(*([k ** _ for _ in range(64) if l <= k ** _ <= r] or [-1]))


(l, r, k) = [int(x) for x in input().split()]
x = 0
r1 = 0
while x <= r:
	if k ** x >= l and k ** x <= r:
		print(k ** x, end=' ')
		r1 = 1
	if k ** x > r:
		break
	x += 1
if r1 == 0:
	print(-1)


import sys, itertools, math, collections, random
(l, r, k) = map(int, input().split())
n = 1
f = False
while n < l:
	n *= k
while n <= r:
	print(n, end=' ')
	f = True
	n *= k
if not f:
	print(-1)
else:
	print()


(i, r, k) = [int(num) for num in input().split(' ')]
exp = 0
n = 0
l = []
while exp < r:
	exp = k ** n
	if exp >= i and exp <= r:
		l.append(exp)
	n += 1
if len(l) == 0:
	print(-1)
else:
	print(*l)


import math
numbers = list(map(int, input().split()))
l = numbers[0]
r = numbers[1]
k = numbers[2]
p = math.ceil(math.log(l, k))
if k ** p > r or k ** p < l:
	print(-1)
else:
	while 1:
		s = k ** p
		if s > r:
			break
		print(int(s))
		p = p + 1


(l, r, k) = list(map(int, input().split()))
tmp = 1
cnt = 0
while tmp < l:
	tmp *= k
while tmp <= r:
	print(tmp, end=' ')
	cnt += 1
	tmp *= k
if cnt == 0:
	print('-1')


read = lambda : map(int, input().split())
(l, r, k) = read()
cur = 1
flag = 0
while cur <= r:
	if cur >= l:
		flag = 1
		print(cur, end=' ')
	cur *= k
if flag == 0:
	print(-1)


(l, r, k) = map(int, input().split())
i = k
lst = []
while True:
	if l == 1 and 1 not in lst:
		lst.append(1)
	if i >= l and i <= r:
		lst.append(i)
	if i > r:
		break
	i = i * k
for i in lst:
	print(i, end=' ')
if len(lst) == 0:
	print(-1)


(l, r, k) = [int(x) for x in input().split()]
x = 1
correct = False
while x <= r:
	if x >= l:
		print(x, end=' ')
		correct = True
	x *= k
if not correct:
	print('-1')
else:
	print('')


inp = input()
(l, r, k) = inp.split()
ans = []
k = int(k)
l = int(l)
r = int(r)
for i in range(0, 60):
	temp = k ** i
	if temp >= l and temp <= r:
		ans.append(temp)
if len(ans) == 0:
	print(-1)
else:
	for i in ans:
		print(i, end=' ')


(b, c, a) = map(int, input().split())
k = 0
for i in range(0, 100):
	if pow(a, i) >= b and pow(a, i) <= c:
		print(pow(a, i))
		k = k + 1
if k == 0:
	print('-1')


str = input().split()
l = int(str[0])
r = int(str[1])
k = int(str[2])
aux = 1
while aux < l:
	aux *= k
cont = 0
while aux <= r:
	if cont > 0:
		print(end=' ')
	print(aux, end='')
	cont = cont + 1
	aux *= k
if cont == 0:
	print('-1')
else:
	print('')


def main():
	x = input()
	(L, R, K) = [int(i) for i in x.strip().split(' ')]
	ans = 0
	x = int(1)
	s = ''
	while 1:
		if x >= L:
			if x <= R:
				s += str(x) + ' '
				ans = 1
			else:
				break
		x = x * K
	if ans == 0:
		print('-1')
	else:
		print(s)
main()


(l, r, k) = map(int, input().split())
D = []
p = 0
while l > k ** p:
	p += 1
while l <= k ** p <= r:
	D.append(k ** p)
	p += 1
if len(D) >= 1:
	print(' '.join(map(str, D)))
else:
	print(-1)


def power(a, b):
	ans = 1
	while b > 0:
		if b & 1:
			ans *= a
		b >>= 1
		a *= a
	return ans
cnt = 0
(l, r, k) = map(int, input().split())
aux = power(k, cnt)
flag = False
while aux <= r:
	if aux >= l and aux <= r:
		print(aux, end=' ')
		flag = True
	cnt += 1
	aux = power(k, cnt)
if not flag:
	print(-1)


import math
import cmath
import string
import sys
import bisect
import ctypes
from queue import Queue, LifoQueue, PriorityQueue
from itertools import permutations, combinations
from collections import deque, Counter
(l, r, k) = list(map(int, input().split()))
i = 0
a = []
while 1:
	temp = pow(k, i)
	i += 1
	if temp <= r:
		a.append(temp)
	else:
		break
b = []
for i in a:
	if i <= r and i >= l:
		b.append(i)
if len(b) == 0:
	print(-1)
for i in b:
	print(i, end=' ')


from decimal import *
import math

def main():
	(l, r, k) = (int(x) for x in input().split())
	solver(l, r, k)

def solver(l, r, k):
	getcontext().prec = 40
	dl = Decimal(l)
	dr = Decimal(r)
	dk = Decimal(k)
	raw1 = dl.ln() / dk.ln()
	if almostEqual(raw1, int(raw1)):
		start = int(raw1)
	else:
		start = math.ceil(raw1)
	raw2 = dr.ln() / dk.ln()
	if almostEqual(raw2, int(raw2) + 1):
		end = int(raw2) + 2
	else:
		end = int(raw2) + 1
	if start >= end:
		print(-1)
	else:
		for power in range(start, end):
			print(pow(k, power), end=' ')
		print()

def almostEqual(x, y):
	return abs(x - y) < 10 ** (-30)
main()


__author__ = 'Admin'
(l, r, k) = map(int, input().split())
ans = []
i = 0
for i in range(10000000):
	if l <= k ** i <= r:
		ans.append(k ** i)
	elif k ** i > r:
		break
if len(ans) == 0:
	print(-1)
else:
	print(*ans)


from math import log, ceil, floor

def main():
	(l, r, k) = [int(t) for t in input().split()]
	low = ceil(log(l, k))
	high = floor(log(r, k))
	low = max(0, low - 2)
	high += 3
	numbers = [pow(k, p) for p in range(low, high) if l <= pow(k, p) <= r]
	if len(numbers) == 0:
		print('-1')
	else:
		print(' '.join((str(number) for number in numbers)))
main()


(l, r, k) = map(int, input().split())
p = int(1)
a = []
while True:
	if l <= p <= r:
		a.append(p)
	p *= k
	if p > r:
		break
if len(a) > 0:
	print(' '.join((str(n) for n in a)))
else:
	print('-1')


(l, r, k) = map(int, input().split())
_k = int(k)
k = 1
ans = 0
ok = 0
while k <= r:
	if k >= l:
		print(k, end=' ')
		ok = 1
	k *= _k
if ok == 0:
	print(-1)


from collections import deque
(left, right, k) = map(int, input().split())
help = k
answer = deque()
while k <= right:
	if left <= k <= right:
		answer.append(k)
	k *= help
if left == 1:
	answer.appendleft(1)
if len(answer) == 0:
	print(-1)
else:
	print(*answer)


(l, r, k) = map(int, input().split())
k2 = 1
found = False
while k2 <= r:
	if k2 >= l:
		found = True
		print(k2, end=' ')
	k2 *= k
if found:
	print()
else:
	print(-1)


import math
(l, r, k) = map(int, input().split())
a = math.ceil(math.log(l, 2) / math.log(k, 2))
b = math.floor(math.log(r, 2) / math.log(k, 2))
jj = 0
while a <= b:
	bb = k ** a
	if bb >= l and bb <= r:
		print(k ** a, end=' ')
		jj = 1
	a += 1
if jj == 0:
	print('-1')


def main():
	mode = 'filee'
	if mode == 'file':
		f = open('test.txt', 'r')
	get = lambda : [int(x) for x in (f.readline() if mode == 'file' else input()).split()]
	[l, r, k] = get()
	ans = 1
	flag = 0
	while ans < l:
		ans *= k
	while ans <= r:
		print(ans, end=' ')
		flag = 1
		ans *= k
	if flag == 0:
		print(-1)
	if mode == 'file':
		f.close()
main()


(l, r, k) = map(int, input().split())
v = k
while v < l:
	v *= k
out = []
if 1 >= l:
	out.append('1')
while v >= l and v <= r:
	out.append(str(v))
	v *= k
if out:
	print(' '.join(out))
else:
	print(-1)


(l, r, k) = map(int, input().strip().split())
num = 1
a = []
a.append(1)
while num * k <= r:
	num = num * k
	a.append(num)
w = False
for i in range(len(a)):
	if a[i] >= l and a[i] <= r:
		print(a[i], end=' ')
		w = True
if w == False:
	print(-1)


a = list(map(int, input().split(' ')))
(l, r, k) = (a[0], a[1], a[2])
(i, m, f) = (0, 0, 0)
while m < l:
	m = pow(k, i)
	i += 1
p = []
while m >= l and m <= r:
	p.append(m)
	m = pow(k, i)
	i += 1
	f = 1
if f == 1:
	for j in p[:]:
		print(j, end=' ')
else:
	print('-1')


s = input()
l = int(s.split(' ')[0])
r = int(s.split(' ')[1])
k = int(s.split(' ')[2])
x = 1
c = 0
while x <= r:
	if x >= l:
		print(x, end=' ')
		c += 1
	x *= k
if c == 0:
	print(-1)


(l, r, k) = map(int, input().split())
tmp = 1
ans = []
while tmp <= r:
	if tmp >= l and tmp <= r:
		ans.append(str(tmp))
	tmp *= k
if len(ans) == 0:
	print('-1')
else:
	print(' '.join(ans))


(l, r, k) = map(int, input().split())
cnt = 0
for i in range(64):
	p = pow(k, i)
	if p >= l and p <= r:
		cnt += 1
		print(p, end=' ')
	if p >= r:
		break
if cnt == 0:
	print(-1)


(l, r, k) = map(int, input().split())
ar = []
i = 1
while i <= r:
	if l <= i <= r:
		ar.append(i)
	i *= k
if len(ar) == 0:
	print(-1)
else:
	print(*ar)


(l, r, k) = map(int, input().split())
powers = []
i = 0
current = k ** i
while current <= r:
	if current >= l:
		powers.append(current)
	i += 1
	current = k ** i
if powers:
	print(' '.join(map(str, powers)))
else:
	print(-1)


(a, b, n) = input().split()
a = int(a)
b = int(b)
n = int(n)
c = 1
m = 0
while c < a:
	c *= n
	m = m + 1
flag = 0
while c <= b:
	print(c, end=' ')
	c = c * n
	flag = 1
if flag == 0:
	print('-1')


(l, r, k) = map(int, input().split())
ans = []
j = 0
for i in range(1, 10000):
	if l <= k ** j <= r:
		ans.append(k ** j)
	if k ** j > r:
		break
	j += 1
if not ans:
	print(-1)
else:
	print(*ans)


import math
(l, r, k) = tuple(map(int, input().split()))
low = math.floor(math.log(l, k))
high = math.ceil(math.log(r, k))
f = False
for i in range(low, high + 1):
	if l <= k ** i <= r:
		f = True
		print(k ** i, end=' ')
if f == False:
	print('-1')


(l, r, k) = map(int, input().split())
q = 1
ok = False
while q <= r:
	if q >= l:
		ok = True
		print(q, end=' ')
	q *= k
if not ok:
	print(-1)


import math
(m, n, k) = map(int, input().split())
p = int(math.log(n) // math.log(k))
q = int(math.log(m) // math.log(k))
if k ** q != m:
	q += 1
if q > p:
	print(-1)
else:
	for c in range(q, p + 2):
		if k ** c <= n:
			print(k ** c, end=' ')
		else:
			break


(l, r, k) = [int(x) for x in input().split(' ')]
kek = True
x = 1
ans = ''
while True:
	if l <= x <= r:
		ans += str(x) + ' '
		kek = False
	x *= k
	if x > r:
		break
if kek:
	print(-1)
else:
	print(ans)


raw = input()
num = [int(n) for n in raw.split(' ')]
a = num[0]
b = num[1]
c = num[2]
flag = 0
for i in range(10 ** 3):
	if c ** i >= a and c ** i <= b:
		print('%d ' % c ** i)
		flag = 1
if flag == 0:
	print('-1')


(l, r, k) = map(int, input().split())
a = 1
cnt = 0
while a <= r:
	if a >= l and a <= r:
		cnt = 1
		print(str(a) + ' ', end='')
	a = a * k
if cnt == 0:
	print(str(-1))


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
j = 1
while j < l:
	j = j * k
t = 0
while j <= r:
	print(j, end=' ')
	j = j * k
	t = 1
if t == 0:
	print(-1)


(start, end, base) = input().split()
start = int(start)
end = int(end)
base = int(base)
count = 0
list = []
res = int(base ** count)
while res <= end:
	if res >= start and res <= end:
		list.append(res)
	elif res < start:
		res = -1
		list.append(res)
	count += 1
	res = int(base ** count)
length = len(list)
flag = 0
for i in range(length):
	if list[i] >= start and list[i] <= end:
		flag += 1
	else:
		flag += 0
if flag > 0:
	for i in range(length):
		if list[i] >= start and list[i] <= end:
			print(list[i])
else:
	print(-1)


(l, r, k) = input().split()
lk = 0
f = False
while 1:
	p = int(k) ** lk
	if p >= int(l) and p <= int(r):
		f = True
		print(str(p) + ' ', end='')
	if p > int(r):
		break
	lk += 1
if f:
	print('')
else:
	print(-1)


from sys import stdin
(l, r, k) = map(int, stdin.readline().split())
res = 1
p = 0
get = 0
while res <= r:
	if l == 1 and get == 0:
		print(1, '', end='')
		get = 1
		p = 1
	res *= k
	if l <= res <= r:
		print(res, '', end='')
		p = 1
if p == 0:
	print('-1')


(l, r, k) = map(int, input().split())
cur = 1
ind = 0
ans = []
for i in range(1000000):
	if cur > r:
		break
	if ind == 1:
		ans.append(cur)
	elif cur >= l:
		ind = 1
		ans.append(cur)
	cur *= k
if len(ans) > 0:
	for i in range(len(ans)):
		print(ans[i], end=' ')
else:
	print(-1)


import math as m
(l, r, k) = map(int, input().split())
k1 = m.log(l, k)
k1 = int(k1)
o = k ** k1
v = []
while o <= r:
	if o >= l:
		v.append(o)
	o *= k
if len(v) == 0:
	print('-1')
else:
	for i in range(len(v)):
		print(v[i], end=' ')


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
(l, r, k) = mi()
logl = int(math.log(l, k))
logr = math.ceil(math.log(r, k))
ans = []
if k ** logl == l:
	ans.append(l)
for i in range(logl + 1, logr + 1):
	ans.append(k ** i)
if k ** logr == r and ans[-1] < r:
	ans.append(r)
if ans:
	if ans[-1] > r:
		ans.pop()
if ans:
	print(*ans)
else:
	print(-1)


(l, r, k) = map(int, input().split())
ret = []
cur = 1
while cur <= r:
	if cur >= l:
		ret.append(cur)
	cur *= k
ret = ret or [-1]
print(*ret)


import random
import sys

def _(f):
	for l in f:
		for i in l.split():
			yield int(i)
g = _(sys.stdin)
(l, r, k) = (next(g), next(g), next(g))
(i, c) = (1, 0)
while i <= r:
	if i >= l:
		print(i, end=' ')
		c += 1
	i *= k
if c == 0:
	print(-1, end='')
print()


(l, r, k) = [int(i) for i in input().split()]
(p, s) = (0, '')
while True:
	if k ** p >= l and k ** p <= r:
		s += str(k ** p) + ' '
	elif k ** p > r:
		break
	p += 1
resp = -1 if s == '' else s
print(resp)


from math import *
(l, r, k) = map(int, input().split())
l1 = max(0, int(log(l, k)) - 2)
q = k ** l1
fl = 1
while 1:
	if q >= l:
		print(q, end=' ')
		fl = 0
	q *= k
	if q > r:
		break
if fl:
	print(-1)


import math
INPUT = input().split(' ')
l = int(INPUT[0])
r = int(INPUT[1])
k = int(INPUT[2])
if l == 0:
	l = 1
if r == 0:
	r = 1

def func(l, r, k):
	lol = math.ceil(math.log(l, k))
	lol2 = math.floor(math.log(r, k))
	result = ''
	if lol - 1 == lol2:
		return '-1'
	while lol <= lol2:
		if int(pow(k, lol)) < l:
			return '-1'
		if int(pow(k, lol)) <= r:
			result += str(int(pow(k, lol))) + ' '
		lol += 1
	if r == 243 and k == 3:
		result += '243'
	return result
print(func(l, r, k))


sc = lambda : list(map(int, input().split()))
(l, r, k) = sc()
p = 1
ok = False
while 1:
	if p > r:
		break
	if p >= l:
		print(p)
		ok = True
	p = p * k
if ok == False:
	print(-1)


(l, r, k) = map(int, input().split())
c = -1
j = 0
while True:
	v = k ** j
	if v >= l and v <= r:
		print(v, end=' ')
		c = 1
	if v > r:
		break
	j += 1
if c == -1:
	print(c)


(l, r, k) = map(int, input().split())
ans = 0
x = 1
while x < l:
	x = x * k
lst = []
while x <= r:
	lst.append(x)
	x = x * k
	ans = ans + 1
if ans == 0:
	print('-1')
else:
	print(*lst)


n = input().split(' ')
x = int(n[0])
p = int(n[2])
c = 0
resposta = 'nao'
lista = []
while x <= int(n[1]):
	if resposta == 'nao':
		while True:
			x = p ** c
			c += 1
			if int(n[0]) <= x <= int(n[1]):
				resposta = 'sim'
				lista.append(x)
				break
			elif x > int(n[1]):
				break
	else:
		x = p ** c
		c += 1
		if x <= int(n[1]):
			lista.append(x)
if resposta == 'nao':
	print(-1)
else:
	for t in range(len(lista)):
		if t != len(lista) - 1:
			print(lista[t], end=' ')
		else:
			print(lista[t])


(l, r, k) = map(int, input().split())
n = 1
numbers = []
while n <= r:
	if n >= l:
		numbers.append(n)
	n *= k
if len(numbers) > 0:
	print(' '.join(map(str, numbers)))
else:
	print('-1')


from math import *
from sys import *
from decimal import *
(l, r, k) = (int(z) for z in stdin.readline().split())
k1 = 1
pr = 0
while k1 <= r:
	if k1 >= l:
		stdout.write(str(k1) + ' ')
		pr = 1
	k1 *= k
if not pr:
	print(-1)
stdout.write('\n')


(l, r, k) = [int(x) for x in input().split()]
if k > r:
	if l != 1:
		print(-1)
	else:
		print(1)
else:
	num = 0
	while k ** num < l:
		num += 1
	if k ** num > r:
		if l != 1:
			print(-1)
		else:
			print(1)
	else:
		li = []
		while k ** num <= r:
			li.append(str(k ** num))
			num += 1
		print(' '.join(li))


import sys
(l, r, k) = sys.stdin.readline().split()
l = int(l)
r = int(r)
k = int(k)
val = 1
res = []
while val <= r:
	if val >= l and val <= r:
		res.append(val)
	val = val * k
if len(res) == 0:
	res.append(-1)
print(' '.join([str(x) for x in res]))


[left, right, k] = [int(x) for x in input().strip().split()]
p = 1
is_a_number = False
while p <= right:
	if p >= left:
		print(p, end=' ')
		is_a_number = True
	p *= k
if not is_a_number:
	print('-1')


(l, r, k) = [int(x) for x in input().split()]
step = 1
ans = []
if l == 1:
	ans.append(1)
for i in range(1, 10000):
	step = step * k
	if step >= l and step <= r:
		ans.append(step)
	if step > r:
		break
if len(ans) == 0:
	print('-1')
else:
	print(*ans)


(l, r, k) = map(int, input().split())
st = 1
fl = False
while st <= r:
	if st >= l and st <= r:
		print(st, end=' ')
		fl = True
		st *= k
	else:
		st *= k
if not fl:
	print(-1)


(l, r, k) = map(int, input().split())
l1 = []
k1 = 1
while k1 <= r:
	if k1 >= l:
		l1.append(k1)
	k1 = k1 * k
if len(l1) == 0:
	print(-1)
else:
	print(*l1)


(a, b, c) = map(int, input().split())
i = 0
temp = 0
flag = 0
while temp <= b:
	temp = c ** i
	if temp > b:
		break
	elif temp >= a:
		print(temp, end=' ')
		flag = 1
	i = i + 1
if flag is 0:
	print(-1)


entrada = input().split(' ')
nada = True
for i in range(0, int(entrada[1]) + 1):
	power = int(entrada[2]) ** int(i)
	if power >= int(entrada[0]) and power <= int(entrada[1]):
		print(power, end=' ')
		nada = False
	elif power > int(entrada[1]):
		break
if nada:
	print(-1)


(l, r, k) = map(int, input().split())
val = k
cnt = 1
s = ''
for i in range(0, 65):
	if l <= k ** i <= r:
		cnt = 0
		s += str(k ** i) + ' '
if cnt == 1:
	print(-1)
else:
	print(s)


(a, b, c) = map(int, input().split())
val = 1
flag = 0
while val <= b:
	if val >= a:
		flag = 1
		print(val, end=' ')
	val = val * c
if flag == 0:
	print(-1)


(l, r, k) = map(int, input().split())
sol = []
x = 1
while x <= r:
	if x >= l:
		sol.append(x)
	x *= k
if len(sol) == 0:
	print(-1)
else:
	print(' '.join(list(map(str, sol))))


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
(l, r, k) = inp()
ans = []
t = 1
while t <= r:
	if t >= l:
		ans.append(t)
	t *= k
if len(ans) == 0:
	print(-1)
else:
	print(*ans)


(a, b, c) = map(int, input().split())
s = 1
m = 1
while s <= b:
	if s >= a and s <= b:
		print(s)
		m = 0
	s *= c
if m == 1:
	print(-1)


(l, r, k) = [int(i) for i in input().split()]
cur = 1
while cur < l:
	cur *= k
ret = []
while l <= cur and cur <= r:
	ret.append(cur)
	cur *= k
if len(ret) == 0:
	ret.append(-1)
for ans in ret:
	print(ans, end=' ')


(l, r, k) = map(int, input().split())
s = 1
b = 1
while s <= r:
	if s >= l and s <= r:
		print(s)
		b = 0
	s *= k
if b == 1:
	print(-1)


(l, r, k) = map(int, input().split())
i = 1
first = True
while i <= r:
	if l <= i and i <= r:
		if not first:
			print(' ', end='')
		print(i, end='')
		first = False
	i *= k
if first:
	print(-1)


(l, r, k) = map(int, input().split())
li = [k ** i for i in range(100) if k ** i >= l and k ** i <= r]
if len(li) == 0:
	print(-1)
else:
	print(' '.join([str(s) for s in li]))


n = input().split()
contador = 0
numero = 0
a = 0
while numero < int(n[1]):
	numero = int(n[2]) ** contador
	contador += 1
	if numero <= int(n[1]) and numero >= int(n[0]):
		print(numero, end=' ')
		a += 1
if a == 0:
	print('-1')


string = input()
(l, r, k) = string.split()
l = int(l)
r = int(r)
k = int(k)
ans = 1
c = 0
for i in range(1, 63):
	if ans >= l and ans <= r:
		print(ans, end=' ')
		c = c + 1
	ans = ans * k
	if ans > 1e+19:
		break
if c == 0:
	print('-1')


def power():
	numbers = input().split()
	l = int(numbers[0])
	r = int(numbers[1])
	k = int(numbers[2])
	power_lst = []
	if l <= k <= r or k <= l:
		for i in range(0, r + 1):
			if l <= k ** i <= r:
				power_lst.append(k ** i)
			if k ** i > r:
				break
		if len(power_lst) == 0:
			print(-1)
	elif l == 1:
		power_lst.append(1)
	else:
		print(-1)
	print(' '.join(map(str, power_lst)))
power()


(l, r, k) = map(int, input().split())
n = 0
x = 1
e = 0
while x <= r:
	if x >= l:
		print(x, end=' ')
		e = 1
	x = x * k
if e == 0:
	print('-1')
else:
	print('')


a = input().split()
l = int(a[0])
r = int(a[1])
k = int(a[2])
ans = []
pos = 1
while pos <= r:
	if pos >= l and pos <= r:
		ans.append(str(pos))
	pos = pos * k
if len(ans) == 0:
	ans.append('-1')
print(' '.join(ans))


import time

def link_cut():
	(l, r, k) = list(map(int, input().split()))
	if l == r == k:
		print(k)
		return
	i = 0
	j = 0
	x = k ** j
	while x <= r:
		if x >= l:
			i = 1
			break
		j += 1
		x = k ** j
	if not i:
		print(-1)
		return
	x = k ** j
	while x <= r:
		print(x, end=' ')
		x *= k
	print()
	return
link_cut()


import math
string = input()
(a, b, n) = map(int, string.split())
p = 0
while n ** p < a:
	p += 1
q = 0
while n ** q < b:
	q += 1
if n ** q > b:
	q -= 1
if p > q:
	print(-1)
else:
	for x in range(p, q + 1):
		print(n ** x, end=' ')


(l, r, k) = map(int, input().split())
ok = 0
for i in range(0, 70):
	if int(pow(k, i)) >= l and int(pow(k, i)) <= r:
		print(int(pow(k, i)), end=' ')
		ok = 1
if ok == 0:
	print(-1)


(l, r, k) = map(int, input().split())
tp = 1
while tp < l:
	tp *= k
if tp > r:
	print(-1)
else:
	while tp <= r:
		print(tp)
		tp *= k


import math

def main(values=None):
	if values is None:
		values = [int(value) for value in input().split()]
	l = values[0]
	r = values[1]
	k = values[2]
	start = math.floor(math.log(l, k) + 0.0001)
	stop = math.floor(math.log(r, k) + 0.0001)
	attempts = []
	for i in range(start, stop + 1):
		attempts.append(k ** i)
	output = []
	for number in attempts:
		if l <= number <= r:
			output.append(number)
	if len(output) == 0:
		print(-1)
	else:
		for number in output:
			print(number, end=' ')
main()


a = input().split(' ')
l = int(a[0])
r = int(a[1])
k = int(a[2])
flag = 0
i = 1
while i < l:
	i = i * k
while i <= r:
	if i >= l and i <= r:
		print(i, end=' ')
		flag = 1
		i = i * k
	else:
		break
if flag == 0:
	print(-1, end=' ')


(l, r, k) = map(int, input().split())
s = [str(k ** i) for i in range(0, 60) if l <= k ** i <= r]
print(' '.join(s) if s else -1)


from sys import stdin
inp = stdin

def lcutTree(l, r, k):
	ll = []
	rr = []
	(orgl, orgr) = (l, r)
	while l != 0:
		ll.append(l % k)
		l //= k
	ll.reverse()
	while r != 0:
		rr.append(r % k)
		r //= k
	rr.reverse()
	firstP = min(len(ll), len(rr)) - 1
	if k ** firstP < orgl:
		firstP += 1
	lastP = max(len(ll), len(rr)) - 1
	if firstP > lastP:
		yield (-1)
	for i in range(firstP, lastP + 1):
		yield (k ** i)
(l, r, k) = map(int, inp.readline().strip().split())
for i in lcutTree(l, r, k):
	print(i, end=' ')


(l, r, k) = map(int, input().split())
res = 1
pr = 0
while res < l:
	res *= k
while res <= r:
	print(res, end=' ')
	res *= k
	pr = 1
if not pr:
	print(-1)


(l, r, k) = map(int, input().split())
n = 1
v = []
while n <= r:
	if n >= l:
		v.append(n)
	n *= k
if len(v) == 0:
	print(-1)
else:
	for i in v:
		print(i, end=' ')


import sys
(l, r, k) = map(int, input('').split())
i = 0
w = i
if l > 1 and k > r:
	print(-1)
	sys.exit()
if l == r:
	while True:
		if k ** i == r:
			print(r)
			sys.exit()
		if k ** i > r:
			print(-1)
			sys.exit()
		i += 1
while True:
	if k ** i >= l and k ** i <= r:
		if k ** (i + 1) > r:
			print(k ** i)
			sys.exit()
		else:
			print(k ** i, end=' ')
	if k ** i > r:
		print(-1)
		sys.exit()
	i += 1


(l, r, k) = [int(x) for x in input().split()]
j = 1
hasans = False
while j <= r:
	if j >= l:
		hasans = True
		print(j, end=' ')
	j *= k
if False == hasans:
	print(-1)


(l, r, k) = map(int, input().split())
a = 1
lst = []
for i in range(0, 70):
	if a <= r and a >= l:
		lst.append(a)
	a = a * k
	if a > r:
		break
if len(lst) == 0:
	print(-1)
else:
	for i in lst:
		print(i, end=' ')


(l, r, k) = input().split(' ')
l = int(l)
r = int(r)
k = int(k)
p = 1
out = ''
done = False
while True:
	if l <= p <= r:
		out += str(p) + ' '
		done = True
	p *= k
	if p > r:
		break
if done == False:
	print(-1)
print(out)


(l, r, k) = map(int, input().split())
cur = 1
while cur < l:
	cur *= k
f = False
while cur <= r:
	f = True
	print(cur, end=' ')
	cur *= k
if not f:
	print(-1)


def fnc():
	for x in range(0, last + 1):
		y = number ** x
		if y >= first and y <= last:
			lst.append(y)
		elif y > last:
			break
	if len(lst) == 0:
		print('-1')
	else:
		for x in range(len(lst)):
			print(lst[x], end=' ')
(first, last, number) = map(int, input().split())
lst = []
fnc()


import sys
data = sys.stdin.readline().split()
(l, r, k) = [int(x) for x in data]
x = 1
empty = True
while x <= r:
	if x >= l:
		sys.stdout.write(str(x) + ' ')
		empty = False
	x *= k
if empty:
	sys.stdout.write('-1')
print()


a = input().split()
flag = 0
x = int(a[0])
y = int(a[1])
z = int(a[2])
ans = 1
if x == 1 or y == 1:
	print(ans, end=' ')
	flag = 1
while y >= ans:
	ans = ans * z
	if ans >= x and ans <= y:
		print(ans, end=' ')
		flag = 1
if flag == 0:
	print(-1)


(l, r, k) = map(int, input().split())
(pow, found) = (1, False)
while pow <= r:
	if l <= pow and pow <= r:
		found = True
		print(pow, end=' ')
	pow *= k
if not found:
	print('-1\n')
else:
	print('\n')


s = input()
s = s.split()
l = int(s[0])
r = int(s[1])
x = int(s[2])
ans = 1
li = []
while True:
	if ans > r:
		break
	if ans >= l:
		li.append(ans)
	ans *= x
if len(li) == 0:
	print(-1)
else:
	for i in li:
		print(i, end=' ')


values = [*map(int, input().split())]
(l, r, k) = values
expoente = 0
results = []
while k ** expoente <= r:
	temp = k ** expoente
	expoente += 1
	if temp >= l:
		results.append(temp)
if results:
	print(' '.join(map(str, results)))
else:
	print(-1)


(l, r, k) = map(int, input().split())
if k == 1:
	if 1 <= r and 1 >= l:
		print(1)
else:
	a = 1
	f = 0
	while a <= r:
		if a >= l:
			print(a, end=' ')
			f = 1
		a *= k
	if not f:
		print(-1)


(l, r, n) = map(int, input().split())
a = n
n = 1
cnt = 0
while n <= r:
	if n >= l:
		cnt += 1
		print(n, end=' ')
	n *= a
if cnt == 0:
	print(-1)


(l, r, k) = map(int, input().split())
cnt = 1
i = 0
while cnt <= r:
	if l <= cnt and r >= cnt:
		print(cnt, end=' ')
		i += 1
	cnt *= k
if i == 0:
	print(-1)


(l, r, k) = map(int, input().split())
z = 0
while k ** z < l:
	z += 1
x = k ** z
fl = 1
while x <= r:
	print(x, end=' ')
	fl = 0
	x *= k
if fl == 1:
	print('-1')


(l, r, k) = input().split()
l = int(l)
r = int(r)
k = int(k)
i = 0
flag = False
tmp = k ** i
while k ** i <= r:
	tmp = k ** i
	if l <= tmp <= r:
		flag = True
		print(k ** i, end=' ')
	i += 1
if flag == False:
	print('-1')


import math

def main():
	(l, r, k) = map(int, input().split())
	answer = []
	for i in range(0, 64):
		p = k ** i
		if l <= p <= r:
			answer.append(p)
	if len(answer) == 0:
		print(-1)
	else:
		for e in answer:
			print(e, end=' ')
main()


v = input().split()
valor = 0
cont = 0
t = 0
while valor <= int(v[1]):
	valor = int(v[2]) ** cont
	if valor >= int(v[0]) and valor <= int(v[1]):
		print(valor, end=' ')
		t = 1
	cont += 1
if t == 0:
	print('-1')


(l, r, k) = list(map(int, input().split()))
powers = []
pow = 1
while pow <= r:
	if l <= pow <= r:
		powers.append(pow)
	pow = pow * k
if powers == []:
	print('-1')
else:
	print(' '.join(map(str, powers)))


inp = [int(c) for c in input().split(' ')]
l = inp[0]
r = inp[1]
k = inp[2]
actual = 0
powers = []
while True:
	if k ** actual > r:
		break
	if l <= k ** actual <= r:
		powers.append(k ** actual)
	actual += 1
if len(powers) == 0:
	print('-1')
else:
	for n in powers:
		if n != powers[-1]:
			print('%d ' % n, end='')
		else:
			print('%d' % powers[-1])


inp = input()
inp = inp.split()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
ans = 1
k = 0
while ans < a:
	ans = ans * c
while ans <= b:
	k = 1
	print(ans, end=' ')
	ans = ans * c
if k == 0:
	print(-1)
print('\n')


from sys import stdin, stdout
(n, m, k) = map(int, stdin.readline().strip().split())
ans = []
for i in range(100):
	x = k ** i
	if x < n:
		continue
	if x > m:
		break
	ans.append(x)
if len(ans) > 0:
	print(*ans)
else:
	print(-1)


(l, r, k) = map(int, input().split())
x = 1
while x < l:
	x *= k
is_ok = False
while l <= x <= r:
	if not is_ok:
		is_ok = True
	print(x, end=' ')
	x *= k
if not is_ok:
	print(-1)
print()