A #10
W #1 2 3 4 5 7 8 9 11 12 13
T #10
#include <bits/stdc++.h>
using namespace std;
#define int long long
int cnt = 0;
int pow1(int x , int y)
{
int mul = 1;
for(int i = 1;i <= y;i++)
mul *= x;
return mul;
}
bool pd(int a , int b , int c)
{
if(c > b)
return false;
if(pow1(c , cnt) <= b)
return true;
else
return false;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n , m , w;
cin >> n >> m >> w;
if(w > m && n > 1)
{
cout << -1;
return 0;
}
else if(w > m && n >= 1)
{
cout << 1;
return 0;
}
for(int i = n;i <= m;i++)
{
int sum = pow1(w , cnt);
if(sum > m)
return 0;
if(pd(n , m , w) == true)
cout << sum << " ";
cnt++;
}
return 0;
}