CodeForces 614A Link/Cut Tree

时间:2023-03-09 08:54:01
CodeForces 614A Link/Cut Tree
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; long long L,R,K; long long POW(long long m,long long n)
{
long long b=;
while (n)
{
if (n & )
b = (b*m);
n = n >> ;
m = (m*m);
}
return b;
}
int main()
{
scanf("%lld%lld%lld",&L,&R,&K);
long long tmp1=(log(L)/log(K)+0.1);
long long tmp2=(log(R)/log(K)+0.1);
if(POW(K,tmp1)<L) tmp1++;
if(POW(K,tmp2)>R) tmp2--;
if(tmp2<tmp1) printf("-1");
else
{
long long now=POW(K,tmp1);
for(long long i=tmp1; i<=tmp2; i++)
{
printf("%lld",now);
now=now*K;
if(i<tmp2)printf(" ");
else printf("\n");
}
}
return ;
}