听题解说__int128能过》
#include<iostream>
using namespace std;
typedef unsigned long long ll;
ll l,r,w;
inline void print(__int128 x){
if(x > 9)
print(x / 10);
putchar(x % 10 + '0');
}
int main(){
cin>>l>>r>>w;
if (l==1){
cout<<"1 ";
if (w==1) return 0;
} else if (w>r){
cout<<-1;
return 0;
}
__int128 pre=1;
while (pre*w<=r){
pre*=w;
if (pre>=l) print(pre),putchar(' ');
}
return 0;
}