题目链接 CodeForces 614A
::::在要爆long long 时,用除法判断
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
using namespace std;
#define N 100100
#define INF 0x3f3f3f3
typedef unsigned long long LL;
int main()
{
LL l, r, k;
while(~scanf("%I64d%I64d%I64d", &l, &r, &k))
{
if(l>r) swap(l, r);
int f=0;
LL x=1;
if(l==1)
{
printf("1");
f=1;
}
for(int i=1; x<=r; i++)
{
if(x>r/k)
break;
x*=k;
if(x>=l&&x<=r)
{
if(f)
printf(" %I64d", x);
else
{
printf("%I64d", x);
f=1;
}
}
}
if(!f) printf("-1");
printf("
");
}
return 0;
}